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)
381 result->
words[
i] &= ~b->words[
i];
382 }
while (++i < b->nwords);
386 int lastnonzero = -1;
392 result->
words[
i] &= ~b->words[
i];
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)
556 for (
int i = 0;
i < wordnum;
i++)
590 if (
a == NULL ||
b == NULL)
593 shortlen =
Min(
a->nwords,
b->nwords);
597 if ((
a->words[
i] &
b->words[
i]) != 0)
599 }
while (++
i < shortlen);
615 if (
a == NULL ||
b ==
NIL)
623 elog(
ERROR,
"negative bitmapset member not allowed");
626 if (wordnum < a->nwords)
627 if ((
a->words[wordnum] & ((
bitmapword) 1 << bitnum)) != 0)
653 if (
a->nwords >
b->nwords)
659 if ((
a->words[
i] & ~
b->words[
i]) != 0)
661 }
while (++i < a->nwords);
691 elog(
ERROR,
"bitmapset has multiple members");
695 }
while (++wordnum < nwords);
738 }
while (++wordnum < nwords);
770 }
while (++wordnum < nwords);
803 }
while (++wordnum < nwords);
822 elog(
ERROR,
"negative bitmapset member not allowed");
830 if (wordnum >=
a->nwords)
832 int oldnwords =
a->nwords;
836 a->nwords = wordnum + 1;
842 }
while (++i < a->nwords);
847#ifdef REALLOCATE_BITMAPSETS
853 a = bms_copy_and_free(
a);
875 elog(
ERROR,
"negative bitmapset member not allowed");
882#ifdef REALLOCATE_BITMAPSETS
883 a = bms_copy_and_free(
a);
893 if (
a->words[wordnum] == 0 && wordnum ==
a->nwords - 1)
896 for (
int i = wordnum - 1;
i >= 0;
i--)
898 if (
a->words[
i] != 0)
931#ifdef REALLOCATE_BITMAPSETS
932 a = bms_copy_and_free(
a);
938 if (
a->nwords <
b->nwords)
954 }
while (++
i < otherlen);
957#ifdef REALLOCATE_BITMAPSETS
959 result = bms_copy_and_free(result);
986 if (
a->nwords <
b->nwords)
992 a->words[
i] =
b->words[
i];
993 }
while (++i < b->nwords);
995 a->nwords =
b->nwords;
997#ifdef REALLOCATE_BITMAPSETS
1003 a = bms_copy_and_free(
a);
1031#ifdef REALLOCATE_BITMAPSETS
1032 a = bms_copy_and_free(
a);
1039 elog(
ERROR,
"negative bitmapset member not allowed");
1045 a->type = T_Bitmapset;
1046 a->nwords = uwordnum + 1;
1048 else if (uwordnum >=
a->nwords)
1050 int oldnwords =
a->nwords;
1055 a->nwords = uwordnum + 1;
1061 }
while (++i < a->nwords);
1073 if (lwordnum == uwordnum)
1084 while (wordnum < uwordnum)
1088 a->words[uwordnum] |= (~(
bitmapword) 0) >> ushiftbits;
1091#ifdef REALLOCATE_BITMAPSETS
1097 a = bms_copy_and_free(
a);
1127 shortlen =
Min(
a->nwords,
b->nwords);
1132 a->words[
i] &=
b->words[
i];
1134 if (
a->words[
i] != 0)
1136 }
while (++
i < shortlen);
1139 if (lastnonzero == -1)
1146 a->nwords = lastnonzero + 1;
1148#ifdef REALLOCATE_BITMAPSETS
1149 a = bms_copy_and_free(
a);
1172#ifdef REALLOCATE_BITMAPSETS
1173 a = bms_copy_and_free(
a);
1180 if (
a->nwords >
b->nwords)
1189 a->words[
i] &= ~b->words[
i];
1190 }
while (++i < b->nwords);
1194 int lastnonzero = -1;
1200 a->words[
i] &= ~b->words[
i];
1203 if (
a->words[
i] != 0)
1205 }
while (++i < a->nwords);
1208 if (lastnonzero == -1)
1215 a->nwords = lastnonzero + 1;
1218#ifdef REALLOCATE_BITMAPSETS
1219 a = bms_copy_and_free(
a);
1242#ifdef REALLOCATE_BITMAPSETS
1243 b = bms_copy_and_free(
b);
1250#ifdef REALLOCATE_BITMAPSETS
1251 a = bms_copy_and_free(
a);
1258 if (
a->nwords <
b->nwords)
1269 otherlen = other->
nwords;
1274 }
while (++
i < otherlen);
1275 if (other != result)
1278#ifdef REALLOCATE_BITMAPSETS
1279 result = bms_copy_and_free(result);
1317 for (
int wordnum =
WORDNUM(prevbit); wordnum < nwords; wordnum++)
1376 if (
a == NULL || prevbit == 0)
1391 for (
int wordnum =
WORDNUM(prevbit); wordnum >= 0; wordnum--)
#define BITMAPSET_SIZE(nwords)
Bitmapset * bms_replace_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_difference(const Bitmapset *a, const Bitmapset *b)
int bms_prev_member(const Bitmapset *a, int prevbit)
Bitmapset * bms_make_singleton(int x)
Bitmapset * bms_int_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_intersect(const Bitmapset *a, const Bitmapset *b)
uint32 bitmap_hash(const void *key, Size keysize)
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)
Bitmapset * bms_del_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_add_range(Bitmapset *a, int lower, int upper)
Bitmapset * bms_del_member(Bitmapset *a, int x)
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_add_member(Bitmapset *a, int x)
Bitmapset * bms_add_members(Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_union(const Bitmapset *a, const Bitmapset *b)
#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)
bool bms_get_singleton_member(const Bitmapset *a, int *member)
Bitmapset * bms_join(Bitmapset *a, Bitmapset *b)
bool bms_nonempty_difference(const Bitmapset *a, const Bitmapset *b)
Bitmapset * bms_copy(const Bitmapset *a)
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
static Datum hash_any(const unsigned char *k, int keylen)
Assert(PointerIsAligned(start, uint64))
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
void * palloc0(Size size)
#define IsA(nodeptr, _type_)
Datum lower(PG_FUNCTION_ARGS)
Datum upper(PG_FUNCTION_ARGS)
static uint32 DatumGetUInt32(Datum X)
bitmapword words[FLEXIBLE_ARRAY_MEMBER]