Macaulay2 Engine
Loading...
Searching...
No Matches

◆ Table_new()

T * Table_new ( int hint,
int cmpconst void *x, const void *y,
unsigned hashconst void *key )

Definition at line 50 of file table.c.

53{
54 T *table;
55 int i;
56 static int primes[] = {
57 509, 509, 1021, 2053, 4093, 8191, 16381, 32771, 65521, INT_MAX};
58 assert(hint >= 0);
59 for (i = 1; primes[i] < hint; i++)
60 ;
61 table =
62 (T *)getmem(sizeof(*table) + primes[i - 1] * sizeof(table->buckets[0]));
63 table->size = primes[i - 1];
64 table->cmp = cmp ? cmp : cmpatom;
65 table->hash = hash ? hash : hashatom;
66 table->buckets = (struct binding **)(table + 1);
67 for (i = 0; i < table->size; i++) table->buckets[i] = NULL;
68 table->length = 0;
69 table->timestamp = 0;
70 return table;
71}
char * getmem(size_t n)
Definition m2-mem.cpp:74
int size
Definition table.c:30
unsigned timestamp
Definition table.c:34
int length
Definition table.c:33
unsigned(* hash)(const void *key)
Definition table.c:32
int(* cmp)(const void *x, const void *y)
Definition table.c:31
struct T::binding ** buckets
static int cmpatom(const void *x, const void *y)
Definition table.c:48
static unsigned hashatom(const void *key)
Definition table.c:49
#define T
Definition table.c:13

References T::buckets, T::cmp, cmpatom(), getmem(), T::hash, hashatom(), T::length, T::size, T, T::timestamp, and x.

Referenced by exponent_table_new().