Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
bitmapset.h127 linesDownload Raw Back to nodes
1/*-------------------------------------------------------------------------2 *3 * bitmapset.h4 *	  PostgreSQL generic bitmap set package5 *6 * A bitmap set can represent any set of nonnegative integers, although7 * it is mainly intended for sets where the maximum value is not large,8 * say at most a few hundred.  By convention, we always represent the9 * empty set by a NULL pointer.10 *11 *12 * Copyright (c) 2003-2023, PostgreSQL Global Development Group13 *14 * src/include/nodes/bitmapset.h15 *16 *-------------------------------------------------------------------------17 */18#ifndef BITMAPSET_H19#define BITMAPSET_H20 21#include "nodes/nodes.h"22 23/*24 * Forward decl to save including pg_list.h25 */26struct List;27 28/*29 * Data representation30 *31 * Larger bitmap word sizes generally give better performance, so long as32 * they're not wider than the processor can handle efficiently.  We use33 * 64-bit words if pointers are that large, else 32-bit words.34 */35#if SIZEOF_VOID_P >= 836 37#define BITS_PER_BITMAPWORD 6438typedef uint64 bitmapword;		/* must be an unsigned type */39typedef int64 signedbitmapword; /* must be the matching signed type */40 41#else42 43#define BITS_PER_BITMAPWORD 3244typedef uint32 bitmapword;		/* must be an unsigned type */45typedef int32 signedbitmapword; /* must be the matching signed type */46 47#endif48 49typedef struct Bitmapset50{51	pg_node_attr(custom_copy_equal, special_read_write, no_query_jumble)52 53	NodeTag		type;54	int			nwords;			/* number of words in array */55	bitmapword	words[FLEXIBLE_ARRAY_MEMBER];	/* really [nwords] */56} Bitmapset;57 58 59/* result of bms_subset_compare */60typedef enum61{62	BMS_EQUAL,					/* sets are equal */63	BMS_SUBSET1,				/* first set is a subset of the second */64	BMS_SUBSET2,				/* second set is a subset of the first */65	BMS_DIFFERENT				/* neither set is a subset of the other */66} BMS_Comparison;67 68/* result of bms_membership */69typedef enum70{71	BMS_EMPTY_SET,				/* 0 members */72	BMS_SINGLETON,				/* 1 member */73	BMS_MULTIPLE				/* >1 member */74} BMS_Membership;75 76 77/*78 * function prototypes in nodes/bitmapset.c79 */80 81extern Bitmapset *bms_copy(const Bitmapset *a);82extern bool bms_equal(const Bitmapset *a, const Bitmapset *b);83extern int	bms_compare(const Bitmapset *a, const Bitmapset *b);84extern Bitmapset *bms_make_singleton(int x);85extern void bms_free(Bitmapset *a);86 87extern Bitmapset *bms_union(const Bitmapset *a, const Bitmapset *b);88extern Bitmapset *bms_intersect(const Bitmapset *a, const Bitmapset *b);89extern Bitmapset *bms_difference(const Bitmapset *a, const Bitmapset *b);90extern bool bms_is_subset(const Bitmapset *a, const Bitmapset *b);91extern BMS_Comparison bms_subset_compare(const Bitmapset *a, const Bitmapset *b);92extern bool bms_is_member(int x, const Bitmapset *a);93extern int	bms_member_index(Bitmapset *a, int x);94extern bool bms_overlap(const Bitmapset *a, const Bitmapset *b);95extern bool bms_overlap_list(const Bitmapset *a, const struct List *b);96extern bool bms_nonempty_difference(const Bitmapset *a, const Bitmapset *b);97extern int	bms_singleton_member(const Bitmapset *a);98extern bool bms_get_singleton_member(const Bitmapset *a, int *member);99extern int	bms_num_members(const Bitmapset *a);100 101/* optimized tests when we don't need to know exact membership count: */102extern BMS_Membership bms_membership(const Bitmapset *a);103 104/* NULL is now the only allowed representation of an empty bitmapset */105#define bms_is_empty(a)  ((a) == NULL)106 107/* these routines recycle (modify or free) their non-const inputs: */108 109extern Bitmapset *bms_add_member(Bitmapset *a, int x);110extern Bitmapset *bms_del_member(Bitmapset *a, int x);111extern Bitmapset *bms_add_members(Bitmapset *a, const Bitmapset *b);112extern Bitmapset *bms_add_range(Bitmapset *a, int lower, int upper);113extern Bitmapset *bms_int_members(Bitmapset *a, const Bitmapset *b);114extern Bitmapset *bms_del_members(Bitmapset *a, const Bitmapset *b);115extern Bitmapset *bms_join(Bitmapset *a, Bitmapset *b);116 117/* support for iterating through the integer elements of a set: */118extern int	bms_next_member(const Bitmapset *a, int prevbit);119extern int	bms_prev_member(const Bitmapset *a, int prevbit);120 121/* support for hashtables using Bitmapsets as keys: */122extern uint32 bms_hash_value(const Bitmapset *a);123extern uint32 bitmap_hash(const void *key, Size keysize);124extern int	bitmap_match(const void *key1, const void *key2, Size keysize);125 126#endif							/* BITMAPSET_H */127 
codekingpro/portable-devtools · Team Ai