-
Notifications
You must be signed in to change notification settings - Fork 57
/
default_data_config.c
69 lines (55 loc) · 1.64 KB
/
default_data_config.c
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
// Copyright 2018-2021 VMware, Inc.
// SPDX-License-Identifier: Apache-2.0
// A default data_config suitable for simple key/value applications
// using a lexicographical sort-order (memcmp)
//
// This data_config does not support blind mutation operations
#include "platform.h"
#include "splinterdb/default_data_config.h"
#include "splinterdb/splinterdb.h"
#include "util.h"
#include "poison.h"
typedef struct ONDISK {
uint8 type;
uint8 value[0];
} message_encoding;
static int
key_compare(const data_config *cfg, slice key1, slice key2)
{
platform_assert(slice_data(key1) != NULL);
platform_assert(slice_data(key2) != NULL);
return slice_lex_cmp(key1, key2);
}
static void
key_to_string(const data_config *cfg, slice key, char *str, size_t max_len)
{
debug_hex_encode(str, max_len, slice_data(key), slice_length(key));
}
static void
message_to_string(const data_config *cfg,
message msg,
char *str,
size_t max_len)
{
debug_hex_encode(str, max_len, message_data(msg), message_length(msg));
}
/*
* Function to initialize application-specific data_config{} struct
* with default values.
*/
void
default_data_config_init(const size_t max_key_size, // IN
data_config *out_cfg // OUT
)
{
data_config cfg = {
.max_key_size = max_key_size,
.key_compare = key_compare,
.key_hash = platform_hash32,
.merge_tuples = NULL,
.merge_tuples_final = NULL,
.key_to_string = key_to_string,
.message_to_string = message_to_string,
};
*out_cfg = cfg;
}