rpm  5.4.15
rpmbf.h
Go to the documentation of this file.
1 #ifndef H_RPMBF
2 #define H_RPMBF
3 
4 #include <sys/types.h> /* XXX size_t typedef */
5 
12 /*@unchecked@*/
13 extern int _rpmbf_debug;
14 
17 typedef /*@refcounted@*/ struct rpmbf_s * rpmbf;
18 
19 typedef unsigned int __pbm_bits;
20 
21 typedef struct {
22  __pbm_bits bits[1];
23 } pbm_set;
24 
25 #if defined(_RPMBF_INTERNAL)
26 
28 struct rpmbf_s {
29  struct rpmioItem_s _item;
30  size_t m;
31  size_t n;
32  size_t k;
33 /*@relnull@*/
34  unsigned char * bits;
35 #if defined(__LCLINT__)
36 /*@refs@*/
37  int nrefs;
38 #endif
39 };
40 #endif /* _RPMBF_INTERNAL */
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 #if defined(_RPMBF_INTERNAL)
47 
48 /* Bit mask macros. */
49 #define __PBM_NBITS /*@-sizeoftype@*/(8 * sizeof(__pbm_bits))/*@=sizeoftype@*/
50 #define __PBM_IX(d) ((d) / __PBM_NBITS)
51 #define __PBM_MASK(d) ((__pbm_bits) 1 << (((unsigned)(d)) % __PBM_NBITS))
52 #define __PBM_BITS(set) ((__pbm_bits *)(set)->bits)
53 
54 #define PBM_FREE(s) _free(s);
55 #define PBM_SET(d, s) (__PBM_BITS (s)[__PBM_IX (d)] |= __PBM_MASK (d))
56 #define PBM_CLR(d, s) (__PBM_BITS (s)[__PBM_IX (d)] &= ~__PBM_MASK (d))
57 #define PBM_ISSET(d, s) ((__PBM_BITS (s)[__PBM_IX (d)] & __PBM_MASK (d)) != 0)
58 
59 #define PBM_ALLOC(d) xcalloc(__PBM_IX (d) + 1, __PBM_NBITS/8)
60 
67 /*@unused@*/
68 static inline pbm_set * PBM_REALLOC(pbm_set ** sp, int * odp, int nd)
69  /*@modifies *sp, *odp @*/
70 {
71  int i, nb;
72 
73  if (nd > (*odp)) {
74  nd *= 2;
75  nb = __PBM_IX(nd) + 1;
76 /*@-unqualifiedtrans@*/
77  *sp = (pbm_set *) xrealloc(*sp, nb * (__PBM_NBITS/8));
78 /*@=unqualifiedtrans@*/
79  for (i = __PBM_IX(*odp) + 1; i < nb; i++)
80  __PBM_BITS(*sp)[i] = 0;
81  *odp = nd;
82  }
83 /*@-compdef -retalias -usereleased@*/
84  return *sp;
85 /*@=compdef =retalias =usereleased@*/
86 }
87 
88 #endif /* _RPMBF_INTERNAL */
89 
95 /*@unused@*/ /*@null@*/
96 rpmbf rpmbfUnlink (/*@killref@*/ /*@only@*/ /*@null@*/ rpmbf bf)
97  /*@modifies bf @*/;
98 #define rpmbfUnlink(_bf) \
99  ((rpmbf)rpmioUnlinkPoolItem((rpmioItem)(_bf), __FUNCTION__, __FILE__, __LINE__))
100 
106 /*@unused@*/ /*@newref@*/ /*@null@*/
107 rpmbf rpmbfLink (/*@null@*/ rpmbf bf)
108  /*@modifies bf @*/;
109 #define rpmbfLink(_bf) \
110  ((rpmbf)rpmioLinkPoolItem((rpmioItem)(_bf), __FUNCTION__, __FILE__, __LINE__))
111 
117 /*@null@*/
118 rpmbf rpmbfFree(/*@killref@*/ /*@null@*/rpmbf bf)
119  /*@modifies bf @*/;
120 #define rpmbfFree(_bf) \
121  ((rpmbf)rpmioFreePoolItem((rpmioItem)(_bf), __FUNCTION__, __FILE__, __LINE__))
122 
130 /*@newref@*/ /*@null@*/
131 rpmbf rpmbfNew(size_t m, size_t k, unsigned flags)
132  /*@*/;
133 
141 int rpmbfAdd(rpmbf bf, const void * _s, size_t ns)
142  /*@modifies bf @*/;
143 
149 int rpmbfClr(rpmbf bf)
150  /*@modifies bf @*/;
151 
159 int rpmbfChk(rpmbf bf, const void * _s, size_t ns)
160  /*@modifies bf @*/;
161 
170 int rpmbfDel(rpmbf bf, const void * _s, size_t ns)
171  /*@modifies bf @*/;
172 
179 int rpmbfIntersect(rpmbf a, const rpmbf b)
180  /*@modifies a @*/;
181 
188 int rpmbfUnion(rpmbf a, const rpmbf b)
189  /*@modifies a @*/;
190 
198 void rpmbfParams(size_t n, double e, size_t * mp, size_t * kp)
199  /*@modifies *mp, *kp @*/;
200 
201 #ifdef __cplusplus
202 }
203 #endif
204 
205 #endif /* H_RPMBF */
const bson * b
Definition: bson.h:280
int rpmbfUnion(rpmbf a, const rpmbf b)
Return union of two Bloom filters.
Definition: rpmbf.c:179
struct rpmbf_s * rpmbf
Definition: rpmbf.h:17
int rpmbfDel(rpmbf bf, const void *_s, size_t ns)
Delete item from a Bloom filter.
Definition: rpmbf.c:132
#define rpmbfLink(_bf)
Definition: rpmbf.h:109
int rpmbfClr(rpmbf bf)
Clear a Bloom filter, discarding all set memberships.
Definition: rpmbf.c:115
int _rpmbf_debug
Definition: rpmbf.c:22
int rpmbfChk(rpmbf bf, const void *_s, size_t ns)
Check for item in a Bloom filter.
Definition: rpmbf.c:90
#define rpmbfUnlink(_bf)
Definition: rpmbf.h:98
void rpmbfParams(size_t n, double e, size_t *mp, size_t *kp)
Return optimal {m, k} for given n and e.
Definition: rpmbf.c:202
const char const bson int mongo_write_concern int flags
Definition: mongo.h:485
int rpmbfIntersect(rpmbf a, const rpmbf b)
Return intersection of two Bloom filters.
Definition: rpmbf.c:156
unsigned int __pbm_bits
Definition: rpmbf.h:19
const char const int i
Definition: bson.h:778
Definition: rpmbf.h:21
int rpmbfAdd(rpmbf bf, const void *_s, size_t ns)
Add item to a Bloom filter.
Definition: rpmbf.c:68
rpmbf rpmbfNew(size_t m, size_t k, unsigned flags)
Create a Bloom filter.
Definition: rpmbf.c:52
#define rpmbfFree(_bf)
Definition: rpmbf.h:120
#define xrealloc
Definition: system.h:35
const char * ns
Definition: mongo.h:326