35 #define WORDNUM(x) ((x) / BITS_PER_BITMAPWORD)
36 #define BITNUM(x) ((x) % BITS_PER_BITMAPWORD)
38 #define BITMAPSET_SIZE(nwords) \
39 (offsetof(Bitmapset, words) + (nwords) * sizeof(bitmapword))
58 #define RIGHTMOST_ONE(x) ((signedbitmapword) (x) & -((signedbitmapword) (x)))
60 #define HAS_MULTIPLE_ONES(x) ((bitmapword) RIGHTMOST_ONE(x) != (x))
63 #if BITS_PER_BITMAPWORD == 32
64 #define bmw_leftmost_one_pos(w) pg_leftmost_one_pos32(w)
65 #define bmw_rightmost_one_pos(w) pg_rightmost_one_pos32(w)
66 #define bmw_popcount(w) pg_popcount32(w)
67 #elif BITS_PER_BITMAPWORD == 64
68 #define bmw_leftmost_one_pos(w) pg_leftmost_one_pos64(w)
69 #define bmw_rightmost_one_pos(w) pg_rightmost_one_pos64(w)
70 #define bmw_popcount(w) pg_popcount64(w)
72 #error "invalid BITS_PER_BITMAPWORD"
89 memcpy(result,
a, size);
101 Assert(
a == NULL ||
a->words[
a->nwords - 1] != 0);
102 Assert(
b == NULL ||
b->words[
b->nwords - 1] != 0);
115 if (
a->nwords !=
b->nwords)
122 if (
a->words[
i] !=
b->words[
i])
124 }
while (++i < a->nwords);
142 Assert(
a == NULL ||
a->words[
a->nwords - 1] != 0);
143 Assert(
b == NULL ||
b->words[
b->nwords - 1] != 0);
147 return (
b == NULL) ? 0 : -1;
152 if (
a->nwords !=
b->nwords)
153 return (
a->nwords >
b->nwords) ? +1 : -1;
162 return (aw > bw) ? +1 : -1;
178 elog(
ERROR,
"negative bitmapset member not allowed");
182 result->type = T_Bitmapset;
183 result->
nwords = wordnum + 1;
224 if (
a->nwords <=
b->nwords)
240 }
while (++
i < otherlen);
257 if (
a == NULL ||
b == NULL)
260 if (
a->nwords <=
b->nwords)
271 resultlen = result->
nwords;
278 if (result->
words[
i] != 0)
280 }
while (++
i < resultlen);
282 if (lastnonzero == -1)
289 result->
nwords = lastnonzero + 1;
302 Assert(
a == NULL ||
a->words[
a->nwords - 1] != 0);
303 Assert(
b == NULL ||
b->words[
b->nwords - 1] != 0);
323 if (result->
nwords >
b->nwords)
333 }
while (++i < b->nwords);
337 int lastnonzero = -1;
346 if (result->
words[
i] != 0)
348 }
while (++i < result->nwords);
351 result->
nwords = lastnonzero + 1;
367 Assert(
a == NULL ||
a->words[
a->nwords - 1] != 0);
368 Assert(
b == NULL ||
b->words[
b->nwords - 1] != 0);
377 if (
a->nwords >
b->nwords)
384 if ((
a->words[
i] & ~
b->words[
i]) != 0)
386 }
while (++i < a->nwords);
402 Assert(
a == NULL ||
a->words[
a->nwords - 1] != 0);
403 Assert(
b == NULL ||
b->words[
b->nwords - 1] != 0);
416 shortlen =
Min(
a->nwords,
b->nwords);
423 if ((aword & ~bword) != 0)
430 if ((bword & ~aword) != 0)
437 }
while (++
i < shortlen);
439 if (
a->nwords >
b->nwords)
446 else if (
a->nwords <
b->nwords)
467 elog(
ERROR,
"negative bitmapset member not allowed");
472 if (wordnum >=
a->nwords)
474 if ((
a->words[wordnum] & ((
bitmapword) 1 << bitnum)) != 0)
502 for (
i = 0;
i < wordnum;
i++)
533 if (
a == NULL ||
b == NULL)
536 shortlen =
Min(
a->nwords,
b->nwords);
540 if ((
a->words[
i] &
b->words[
i]) != 0)
542 }
while (++
i < shortlen);
556 if (
a == NULL ||
b ==
NIL)
564 elog(
ERROR,
"negative bitmapset member not allowed");
567 if (wordnum < a->nwords)
568 if ((
a->words[wordnum] & ((
bitmapword) 1 << bitnum)) != 0)
585 Assert(
a == NULL ||
a->words[
a->nwords - 1] != 0);
586 Assert(
b == NULL ||
b->words[
b->nwords - 1] != 0);
594 if (
a->nwords >
b->nwords)
600 if ((
a->words[
i] & ~
b->words[
i]) != 0)
602 }
while (++i < a->nwords);
629 elog(
ERROR,
"bitmapset has multiple members");
633 }
while (++wordnum < nwords);
673 }
while (++wordnum < nwords);
702 }
while (++wordnum < nwords);
732 }
while (++wordnum < nwords);
759 elog(
ERROR,
"negative bitmapset member not allowed");
766 if (wordnum >=
a->nwords)
768 int oldnwords =
a->nwords;
772 a->nwords = wordnum + 1;
778 }
while (++i < a->nwords);
799 elog(
ERROR,
"negative bitmapset member not allowed");
812 if (
a->words[wordnum] == 0 && wordnum ==
a->nwords - 1)
815 for (
int i = wordnum - 1;
i >= 0;
i--)
817 if (
a->words[
i] != 0)
848 if (
a->nwords <
b->nwords)
864 }
while (++
i < otherlen);
892 elog(
ERROR,
"negative bitmapset member not allowed");
898 a->type = T_Bitmapset;
899 a->nwords = uwordnum + 1;
901 else if (uwordnum >=
a->nwords)
903 int oldnwords =
a->nwords;
908 a->nwords = uwordnum + 1;
914 }
while (++i < a->nwords);
926 if (lwordnum == uwordnum)
937 while (wordnum < uwordnum)
941 a->words[uwordnum] |= (~(
bitmapword) 0) >> ushiftbits;
966 shortlen =
Min(
a->nwords,
b->nwords);
971 a->words[
i] &=
b->words[
i];
973 if (
a->words[
i] != 0)
975 }
while (++
i < shortlen);
978 if (lastnonzero == -1)
985 a->nwords = lastnonzero + 1;
997 Assert(
a == NULL ||
a->words[
a->nwords - 1] != 0);
998 Assert(
b == NULL ||
b->words[
b->nwords - 1] != 0);
1006 if (
a->nwords >
b->nwords)
1015 a->words[
i] &= ~
b->words[
i];
1016 }
while (++i < b->nwords);
1020 int lastnonzero = -1;
1026 a->words[
i] &= ~
b->words[
i];
1029 if (
a->words[
i] != 0)
1031 }
while (++i < a->nwords);
1034 if (lastnonzero == -1)
1041 a->nwords = lastnonzero + 1;
1064 if (
a->nwords <
b->nwords)
1075 otherlen = other->
nwords;
1080 }
while (++
i < otherlen);
1081 if (other != result)
1117 for (wordnum =
WORDNUM(prevbit); wordnum < nwords; wordnum++)
1175 if (
a == NULL || prevbit == 0)
1186 for (wordnum =
WORDNUM(prevbit); wordnum >= 0; wordnum--)
#define BITMAPSET_SIZE(nwords)
#define bmw_rightmost_one_pos(w)
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)
#define bmw_leftmost_one_pos(w)
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_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 BITS_PER_BITMAPWORD
elog(ERROR, "%s: %s", p2, msg)
static Datum hash_any(const unsigned char *k, int keylen)
Assert(fmt[strlen(fmt) - 1] !='\n')
void pfree(void *pointer)
void * palloc0(Size size)
void * repalloc(void *pointer, Size size)
Datum lower(PG_FUNCTION_ARGS)
Datum upper(PG_FUNCTION_ARGS)
static uint32 DatumGetUInt32(Datum X)
bitmapword words[FLEXIBLE_ARRAY_MEMBER]