forked from utsaslab/RECIPE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Key.h
49 lines (36 loc) · 1.11 KB
/
Key.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
#ifndef ART_KEY_H
#define ART_KEY_H
#include <stdint.h>
#include <cstring>
#include <memory>
#include <assert.h>
typedef struct Key {
uint64_t value;
size_t key_len;
uint8_t fkey[];
inline Key *make_leaf(char *key, size_t key_len, uint64_t value);
inline Key *make_leaf(uint64_t key, size_t key_len, uint64_t value);
inline size_t getKeyLen() const;
} Key;
inline Key *Key::make_leaf(char *key, size_t key_len, uint64_t value)
{
void *aligned_alloc;
posix_memalign(&aligned_alloc, 64, sizeof(Key) + key_len);
Key *k = reinterpret_cast<Key *> (aligned_alloc);
k->value = value;
k->key_len = key_len;
memcpy(k->fkey, key, key_len);
return k;
}
inline Key *Key::make_leaf(uint64_t key, size_t key_len, uint64_t value)
{
void *aligned_alloc;
posix_memalign(&aligned_alloc, 64, sizeof(Key) + key_len);
Key *k = reinterpret_cast<Key *> (aligned_alloc);
k->value = value;
k->key_len = key_len;
reinterpret_cast<uint64_t *> (&k->fkey[0])[0] = __builtin_bswap64(key);
return k;
}
inline size_t Key::getKeyLen() const { return key_len; }
#endif // ART_KEY_H