47 #define WORDNUM(x) ((x) / BITS_PER_BITMAPWORD)
48 #define BITNUM(x) ((x) % BITS_PER_BITMAPWORD)
50 #define BITMAPSET_SIZE(nwords) \
51 (offsetof(Bitmapset, words) + (nwords) * sizeof(bitmapword))
70 #define RIGHTMOST_ONE(x) ((signedbitmapword) (x) & -((signedbitmapword) (x)))
72 #define HAS_MULTIPLE_ONES(x) ((bitmapword) RIGHTMOST_ONE(x) != (x))
74 #ifdef USE_ASSERT_CHECKING
90 if (
a->words[
a->nwords - 1] == 0)
97 #ifdef REALLOCATE_BITMAPSETS
134 memcpy(result,
a,
size);
160 if (
a->nwords !=
b->nwords)
167 if (
a->words[
i] !=
b->words[
i])
169 }
while (++i < a->nwords);
192 return (
b == NULL) ? 0 : -1;
197 if (
a->nwords !=
b->nwords)
198 return (
a->nwords >
b->nwords) ? +1 : -1;
207 return (aw > bw) ? +1 : -1;
223 elog(
ERROR,
"negative bitmapset member not allowed");
227 result->type = T_Bitmapset;
228 result->
nwords = wordnum + 1;
267 if (
a->nwords <=
b->nwords)
283 }
while (++
i < otherlen);
304 if (
a == NULL ||
b == NULL)
308 if (
a->nwords <=
b->nwords)
319 resultlen = result->
nwords;
326 if (result->
words[
i] != 0)
328 }
while (++
i < resultlen);
330 if (lastnonzero == -1)
337 result->
nwords = lastnonzero + 1;
372 if (result->
nwords >
b->nwords)
382 }
while (++i < b->nwords);
386 int lastnonzero = -1;
395 if (result->
words[
i] != 0)
397 }
while (++i < result->nwords);
400 result->
nwords = lastnonzero + 1;
426 if (
a->nwords >
b->nwords)
433 if ((
a->words[
i] & ~
b->words[
i]) != 0)
435 }
while (++i < a->nwords);
466 shortlen =
Min(
a->nwords,
b->nwords);
473 if ((aword & ~bword) != 0)
480 if ((bword & ~aword) != 0)
487 }
while (++
i < shortlen);
489 if (
a->nwords >
b->nwords)
496 else if (
a->nwords <
b->nwords)
519 elog(
ERROR,
"negative bitmapset member not allowed");
525 if (wordnum >=
a->nwords)
527 if ((
a->words[wordnum] & ((
bitmapword) 1 << bitnum)) != 0)
557 for (
i = 0;
i < wordnum;
i++)
591 if (
a == NULL ||
b == NULL)
594 shortlen =
Min(
a->nwords,
b->nwords);
598 if ((
a->words[
i] &
b->words[
i]) != 0)
600 }
while (++
i < shortlen);
616 if (
a == NULL ||
b ==
NIL)
624 elog(
ERROR,
"negative bitmapset member not allowed");
627 if (wordnum < a->nwords)
628 if ((
a->words[wordnum] & ((
bitmapword) 1 << bitnum)) != 0)
654 if (
a->nwords >
b->nwords)
660 if ((
a->words[
i] & ~
b->words[
i]) != 0)
662 }
while (++i < a->nwords);
692 elog(
ERROR,
"bitmapset has multiple members");
696 }
while (++wordnum < nwords);
739 }
while (++wordnum < nwords);
771 }
while (++wordnum < nwords);
804 }
while (++wordnum < nwords);
823 elog(
ERROR,
"negative bitmapset member not allowed");
831 if (wordnum >=
a->nwords)
833 int oldnwords =
a->nwords;
837 a->nwords = wordnum + 1;
843 }
while (++i < a->nwords);
848 #ifdef REALLOCATE_BITMAPSETS
854 a = bms_copy_and_free(
a);
876 elog(
ERROR,
"negative bitmapset member not allowed");
883 #ifdef REALLOCATE_BITMAPSETS
884 a = bms_copy_and_free(
a);
894 if (
a->words[wordnum] == 0 && wordnum ==
a->nwords - 1)
897 for (
int i = wordnum - 1;
i >= 0;
i--)
899 if (
a->words[
i] != 0)
932 #ifdef REALLOCATE_BITMAPSETS
933 a = bms_copy_and_free(
a);
939 if (
a->nwords <
b->nwords)
955 }
while (++
i < otherlen);
958 #ifdef REALLOCATE_BITMAPSETS
960 result = bms_copy_and_free(result);
987 if (
a->nwords <
b->nwords)
993 a->words[
i] =
b->words[
i];
994 }
while (++i < b->nwords);
996 a->nwords =
b->nwords;
998 #ifdef REALLOCATE_BITMAPSETS
1004 a = bms_copy_and_free(
a);
1032 #ifdef REALLOCATE_BITMAPSETS
1033 a = bms_copy_and_free(
a);
1040 elog(
ERROR,
"negative bitmapset member not allowed");
1046 a->type = T_Bitmapset;
1047 a->nwords = uwordnum + 1;
1049 else if (uwordnum >=
a->nwords)
1051 int oldnwords =
a->nwords;
1056 a->nwords = uwordnum + 1;
1062 }
while (++i < a->nwords);
1074 if (lwordnum == uwordnum)
1085 while (wordnum < uwordnum)
1089 a->words[uwordnum] |= (~(
bitmapword) 0) >> ushiftbits;
1092 #ifdef REALLOCATE_BITMAPSETS
1098 a = bms_copy_and_free(
a);
1128 shortlen =
Min(
a->nwords,
b->nwords);
1133 a->words[
i] &=
b->words[
i];
1135 if (
a->words[
i] != 0)
1137 }
while (++
i < shortlen);
1140 if (lastnonzero == -1)
1147 a->nwords = lastnonzero + 1;
1149 #ifdef REALLOCATE_BITMAPSETS
1150 a = bms_copy_and_free(
a);
1173 #ifdef REALLOCATE_BITMAPSETS
1174 a = bms_copy_and_free(
a);
1181 if (
a->nwords >
b->nwords)
1190 a->words[
i] &= ~
b->words[
i];
1191 }
while (++i < b->nwords);
1195 int lastnonzero = -1;
1201 a->words[
i] &= ~
b->words[
i];
1204 if (
a->words[
i] != 0)
1206 }
while (++i < a->nwords);
1209 if (lastnonzero == -1)
1216 a->nwords = lastnonzero + 1;
1219 #ifdef REALLOCATE_BITMAPSETS
1220 a = bms_copy_and_free(
a);
1243 #ifdef REALLOCATE_BITMAPSETS
1244 b = bms_copy_and_free(
b);
1251 #ifdef REALLOCATE_BITMAPSETS
1252 a = bms_copy_and_free(
a);
1259 if (
a->nwords <
b->nwords)
1270 otherlen = other->
nwords;
1275 }
while (++
i < otherlen);
1276 if (other != result)
1279 #ifdef REALLOCATE_BITMAPSETS
1280 result = bms_copy_and_free(result);
1319 for (wordnum =
WORDNUM(prevbit); wordnum < nwords; wordnum++)
1379 if (
a == NULL || prevbit == 0)
1390 for (wordnum =
WORDNUM(prevbit); wordnum >= 0; wordnum--)
#define BITMAPSET_SIZE(nwords)
int bms_prev_member(const Bitmapset *a, int prevbit)
uint32 bitmap_hash(const void *key, Size keysize)
Bitmapset * bms_join(Bitmapset *a, Bitmapset *b)
bool bms_equal(const Bitmapset *a, const Bitmapset *b)
BMS_Comparison bms_subset_compare(const Bitmapset *a, const Bitmapset *b)
int bms_next_member(const Bitmapset *a, int prevbit)
uint32 bms_hash_value(const Bitmapset *a)
bool bms_is_subset(const Bitmapset *a, const Bitmapset *b)
int bms_singleton_member(const Bitmapset *a)
void bms_free(Bitmapset *a)
int bms_num_members(const Bitmapset *a)
bool bms_is_member(int x, const Bitmapset *a)
Bitmapset * bms_make_singleton(int x)
Bitmapset * bms_add_member(Bitmapset *a, int x)
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_difference(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_intersect(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_add_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_replace_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_int_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_del_member(Bitmapset *a, int x)
#define HAS_MULTIPLE_ONES(x)
int bitmap_match(const void *key1, const void *key2, Size keysize)
BMS_Membership bms_membership(const Bitmapset *a)
int bms_member_index(Bitmapset *a, int x)
bool bms_overlap(const Bitmapset *a, const Bitmapset *b)
int bms_compare(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_copy(const Bitmapset *a)
bool bms_get_singleton_member(const Bitmapset *a, int *member)
Bitmapset * bms_add_range(Bitmapset *a, int lower, int upper)
bool bms_nonempty_difference(const Bitmapset *a, const Bitmapset *b)
bool bms_overlap_list(const Bitmapset *a, const List *b)
#define bmw_rightmost_one_pos(w)
#define bmw_leftmost_one_pos(w)
#define BITS_PER_BITMAPWORD
#define Assert(condition)
static Datum hash_any(const unsigned char *k, int keylen)
void pfree(void *pointer)
void * palloc0(Size size)
void * repalloc(void *pointer, Size size)
#define IsA(nodeptr, _type_)
Datum lower(PG_FUNCTION_ARGS)
Datum upper(PG_FUNCTION_ARGS)
static uint32 DatumGetUInt32(Datum X)
static pg_noinline void Size size
bitmapword words[FLEXIBLE_ARRAY_MEMBER]