- uint8_t depth = ht->header.start_depth;
- void** pages = ht->pages;
- if (ht_free != NULL)
- { while (pages[depth] != NULL)
- ht_free(pages[depth++]);
- ht_free(ht);
- return NULL;
- }
- return ht;
-}
-
-/********************************************************************************
-*********************************************************************************
-*********************************************************************************
-********************************************************************************/
-typedef struct ston_dht2_header_t
-{ uint16_t val_bytes;
- uint8_t key_bytes;
- uint8_t flags;
-}ston_dht2_h;
-
-typedef struct ston_dht2_bucket_t
-{ uint8_t depth;
- void* page;
- uint32_t count;
-}ston_dht2_bucket_h,* ston_dht2_bucket;
-
-#define STON_DHT_BUCKETS_SIZE (sizeof(void*) * 8)
-typedef struct ston_dht2_t
-{ ston_dht2_h header;
- ston_dht2_bucket_h buckets[1 + STON_DHT_BUCKETS_SIZE];
- ston_dht2_bucket bsp;
- uint32_t row_bytes;
- uint8_t buckets_len;
- void* (*ht_alloc)(size_t);
- void (*ht_free)(void*);
-}* ston_dht2;
-
-STON_FUNC
-ston_dht2 ston_dht2_create(uint16_t,uint8_t,void*(*)(size_t),void(*)(void*));
-STON_FUNC
-uint32_t* ston_dht232_row(ston_dht2,uint32_t);
-STON_FUNC
-uint32_t ston_dht232_insert(ston_dht2,uint32_t,uint16_t,uint32_t);
-STON_FUNC
-size_t ston_dht232_insertx(ston_dht2,uint32_t,uint32_t*,uint16_t,size_t);
-STON_FUNC
-ston_dht2 ston_dht2_free(ston_dht2);
-
-#define ston_dht2_bytes(_HT,_DEPTH) ((_HT)->row_bytes << (_DEPTH))
-#define ston_dht2_new(_COL,_ALOC,_FRE) (ston_dht2_create(_COL,sizeof(int),_ALOC,_FRE))
-#define ston_dht232_new(_COL,_ALOC,_FRE) (ston_dht2_create(_COL,sizeof(uint32_t),_ALOC,_FRE))
-#define ston_dht232_entry(_HT,_KEY,_COL) (ston_dht232_row(_HT,_KEY) + _COL)
-
-
-/* Creates a new bucketted hash table, provided a memory allocation function
- that takes a single size_t bytes, a memory free function, a column count, and
- a row count which determines the size of the buckets.
-*/
-static ston_dht2_bucket_h dummy_bucket = { (uint8_t)-1, NULL, (uint32_t)-1 };
-
-STON_FUNC
-ston_dht2 ston_dht2_create
-( uint16_t val_bytes,
- uint8_t key_bytes,
- void* (*ht_alloc)(size_t),
- void (*ht_free)(void*)
-)
-{ ston_dht2 ht = (ston_dht2) ht_alloc(sizeof(struct ston_dht2_t));
- if (ht != NULL)
- { ht->header.val_bytes = val_bytes;
- ht->header.key_bytes = key_bytes;
- ht->row_bytes = val_bytes + key_bytes;
- ht->ht_alloc = ht_alloc;
- ht->ht_free = ht_free;
- size_t i;
- for (i = 0; i <= STON_DHT_BUCKETS_SIZE; i++)
- ht->buckets[i] = dummy_bucket;
- ht->bsp = ht->buckets + STON_DHT_BUCKETS_SIZE - 1;
- ht->bsp->page = ht_alloc(ston_dht2_bytes(ht, 4));
- if (ht->bsp->page == NULL && ht_free != NULL)
- ht_free(ht);
- else
- { memset((ht->bsp->page), 0, ston_dht2_bytes(ht,4));
- ht->bsp->depth = 4;
- ht->bsp->count = 0;
- ht->buckets_len = 1;
- }
- }