-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdb_object.h
More file actions
71 lines (50 loc) · 2.05 KB
/
db_object.h
File metadata and controls
71 lines (50 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#pragma once
#ifdef _WIN32
#include <intrin.h>
#endif
// number of elements in an array node
// max element idx = ARRAY_size * ARRAY_lvl1
// note that each level zero block reserves first few
// indexes (ARRAY_first) for the inUse bit map
#define ARRAY_size 256 // level zero slot count
#define ARRAY_lvl1 (256 - 2) // adjust to power of two sizeround
// define the number of inUse slots per level zero block
#define ARRAY_inuse ((ARRAY_size + 64 - 1) / 64)
// calculate the number of sluffed indexes because of inUse bit maps
#define ARRAY_first(objsize) ((objsize) ? (ARRAY_inuse * sizeof(uint64_t) + (objsize) - 1) / (objsize) : 0)
// Arrays
typedef struct {
uint16_t level0; // level0 slot to allocate
uint16_t maxLvl0; // number of level one blocks
uint32_t objSize; // size of each array element
DbAddr addr[ARRAY_lvl1]; // level one block addresses
} ArrayHdr;
void *arrayElement(DbMap *map, DbAddr *array, uint16_t idx, uint32_t size);
void *arrayEntry(DbMap *map, DbAddr *array, uint16_t idx);
uint16_t arrayAlloc(DbMap *map, DbAddr *array, uint32_t size);
uint16_t arrayFirst(uint32_t objSize);
void arrayRelease(DbMap *map, DbAddr *array, uint16_t idx);
enum ObjType {
FrameType,
ObjIdType, // ObjId value
MinObjType = 4, // minimum object size in bits
MaxObjType = 50 // each half power of two, 4 - 24
};
// set-membership control
typedef struct {
DbAddr next;
uint16_t cnt; // count of entries in this table
uint16_t max; // number of hash table entries
uint16_t sizeIdx; // hash table size vector slot
uint64_t table[0]; // the hash table entries
} DbMmbr;
DbMmbr *xtnMmbr(DbMap *map, DbAddr *addr, DbMmbr *first);
DbMmbr *iniMmbr(DbMap *map, DbAddr *addr, int minSize);
// mmbr table enumerators
void *getMmbr(DbMmbr *mmbr, uint64_t item);
void *nxtMmbr(DbMmbr *mmbr, uint64_t *entry);
void *allMmbr(DbMmbr *mmbr, uint64_t *entry);
void *revMmbr(DbMmbr *mmbr, uint64_t *entry);
// mmbr-set functions
uint64_t *setMmbr(DbMap *map, DbAddr *addr, uint64_t keyVal, bool add);
uint64_t *newMmbr(DbMap *map, DbAddr *addr, uint64_t keyVal);