CUBRID Engine  latest
query_bitset.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 /*
20  * query_bitset.h - Extendible bitset implementation
21  */
22 
23 #ifndef _QUERY_BITSET_H_
24 #define _QUERY_BITSET_H_
25 
26 #ident "$Id$"
27 
28 #include <stdio.h>
29 #include <string.h>
30 
31 #include "optimizer.h"
32 
33 /*
34  * The maximum number of elements permitted in a set.
35  */
36 
37 #define NELEMENTS 64
38 
39 #define _LOG2_WORDSIZE 5
40 #define _WORDSIZE 32 /* Number of bits in BITSET_CARRIER */
41 #define _MASK ((1L << _LOG2_WORDSIZE) - 1)
42 #define _WORD(x) ((x) >> _LOG2_WORDSIZE)
43 #define _BIT(x) ((x) & _MASK)
44 
45 #define NWORDS (((NELEMENTS + (_WORDSIZE-1)) & ~(_WORDSIZE-1)) \
46  >> _LOG2_WORDSIZE)
47 
48 typedef unsigned int BITSET_CARRIER;
50 
51 struct bitset
52 {
55  int nwords;
56  struct
57  {
59  } set;
60 };
61 
63 {
64  const BITSET *set;
65  int next;
66 };
67 
68 #define BITSET_CLEAR(s) memset((char *)(s).setp, 0, \
69  (s).nwords * sizeof(BITSET_CARRIER))
70 #define BITSET_MEMBER(s, x) ((_WORD(x) < (s).nwords) \
71  && ((s).setp[_WORD(x)] & (1L << _BIT(x))))
72 #define BITPATTERN(s) ((s).setp[0])
73 
74 /*
75  * Use these macros when you have to actually move a bitset from one
76  * region to another; it will maintain the proper self-relative pointer
77  * if necessary. DON'T do DELSET() on the old set after using this
78  * macro!
79  */
80 #define BITSET_MOVE(dst, src) \
81  do { \
82  (dst) = (src); \
83  if ((src).setp == (src).set.word) \
84  (dst).setp = (dst).set.word; \
85  } while(0)
86 
87 extern BITSET EMPTY_SET;
88 
89 #if defined (CUBRID_DEBUG)
90 extern void set_stats (FILE * fp);
91 #endif
92 extern void bitset_extend (BITSET * dst, int nwords);
93 extern void bitset_assign (BITSET *, const BITSET *);
94 extern void bitset_add (BITSET *, int);
95 extern void bitset_remove (BITSET *, int);
96 extern void bitset_union (BITSET *, const BITSET *);
97 extern void bitset_intersect (BITSET *, const BITSET *);
98 extern void bitset_difference (BITSET *, const BITSET *);
99 #if defined(ENABLE_UNUSED_FUNCTION)
100 extern void bitset_invert (BITSET *);
101 extern int bitset_position (const BITSET *, int);
102 #endif
103 extern int bitset_subset (const BITSET *, const BITSET *);
104 extern int bitset_intersects (const BITSET *, const BITSET *);
105 extern int bitset_is_empty (const BITSET *);
106 extern int bitset_is_equivalent (const BITSET *, const BITSET *);
107 extern int bitset_cardinality (const BITSET *);
108 extern int bitset_iterate (const BITSET *, BITSET_ITERATOR *);
109 extern int bitset_next_member (BITSET_ITERATOR *);
110 extern int bitset_first_member (const BITSET *);
111 extern void bitset_print (const BITSET *, FILE * fp);
112 extern void bitset_init (BITSET *, QO_ENV *);
113 extern void bitset_delset (BITSET *);
114 
115 #endif /* _QUERY_BITSET_H_ */
QO_ENV * env
Definition: query_bitset.h:53
unsigned int BITSET_CARRIER
Definition: query_bitset.h:48
int nwords
Definition: query_bitset.h:55
int bitset_is_empty(const BITSET *)
Definition: query_bitset.c:318
void bitset_init(BITSET *, QO_ENV *)
Definition: query_bitset.c:557
int bitset_cardinality(const BITSET *)
Definition: query_bitset.c:393
int bitset_subset(const BITSET *, const BITSET *)
Definition: query_bitset.c:263
BITSET_CARRIER * setp
Definition: query_bitset.h:54
void bitset_extend(BITSET *dst, int nwords)
Definition: query_bitset.c:92
void bitset_delset(BITSET *)
Definition: query_bitset.c:571
int bitset_intersects(const BITSET *, const BITSET *)
Definition: query_bitset.c:295
unsigned int BITSET
Definition: esql_misc.h:94
int bitset_iterate(const BITSET *, BITSET_ITERATOR *)
Definition: query_bitset.c:464
void bitset_assign(BITSET *, const BITSET *)
Definition: query_bitset.c:120
void bitset_difference(BITSET *, const BITSET *)
Definition: query_bitset.c:224
void bitset_intersect(BITSET *, const BITSET *)
Definition: query_bitset.c:200
BITSET EMPTY_SET
Definition: query_bitset.c:64
#define NWORDS
Definition: query_bitset.h:45
void bitset_print(const BITSET *, FILE *fp)
Definition: query_bitset.c:527
int bitset_first_member(const BITSET *)
Definition: query_bitset.c:514
int bitset_next_member(BITSET_ITERATOR *)
Definition: query_bitset.c:478
void bitset_union(BITSET *, const BITSET *)
Definition: query_bitset.c:176
void bitset_add(BITSET *, int)
Definition: query_bitset.c:138
BITSET_CARRIER word[NWORDS]
Definition: query_bitset.h:58
void bitset_remove(BITSET *, int)
Definition: query_bitset.c:158
int bitset_is_equivalent(const BITSET *, const BITSET *)
Definition: query_bitset.c:342