forked from michaeldickens/Typing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjudy64.h
87 lines (73 loc) · 1.88 KB
/
judy64.h
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#ifdef linux
#define _FILE_OFFSET_BITS 64
#define _LARGEFILE_SOURCE
#define __USE_FILE_OFFSET64
#include <endian.h>
#else
#ifdef __BIG_ENDIAN__
#ifndef BYTE_ORDER
#define BYTE_ORDER 4321
#endif
#else
#ifndef BYTE_ORDER
#define BYTE_ORDER 1234
#endif
#endif
#ifndef BIG_ENDIAN
#define BIG_ENDIAN 4321
#endif
#endif
typedef unsigned char uchar;
typedef unsigned int uint;
#if defined(__LP64__) || \
defined(__x86_64__) || \
defined(__amd64__) || \
defined(_WIN64) || \
defined(__sparc64__) || \
defined(__arch64__) || \
defined(__powerpc64__) || \
defined (__s390x__)
// defines for 64 bit
typedef unsigned long long judyvalue;
typedef unsigned long long JudySlot;
#define JUDY_key_mask (0x07)
#define JUDY_key_size 8
#define JUDY_slot_size 8
#define JUDY_span_bytes (3 * JUDY_key_size)
#define JUDY_span_equiv JUDY_2
#define JUDY_radix_equiv JUDY_8
#else
// defines for 32 bit
typedef uint judyvalue;
typedef uint JudySlot;
#define JUDY_key_mask (0x03)
#define JUDY_key_size 4
#define JUDY_slot_size 4
#define JUDY_span_bytes (7 * JUDY_key_size)
#define JUDY_span_equiv JUDY_4
#define JUDY_radix_equiv JUDY_8
#endif
#define JUDY_mask (~(JudySlot)0x07)
// define the alignment factor for judy nodes and allocations
// to enable this feature, set to 64
#define JUDY_cache_line 8 // minimum size is 8 bytes
typedef struct {
void *seg; // next used allocator
uint next; // next available offset
} JudySeg;
typedef struct {
JudySlot next; // judy object
uint off; // offset within key
int slot; // slot within object
} JudyStack;
typedef struct {
JudySlot root[1]; // root of judy array
void **reuse[8]; // reuse judy blocks
JudySeg *seg; // current judy allocator
uint level; // current height of stack
uint max; // max height of stack
JudyStack stack[1]; // current cursor
} Judy;