1/*
2 * vmapx.h
3 *
4 * Copyright (C) 2012-2016 Aerospike, Inc.
5 *
6 * Portions may be licensed to Aerospike, Inc. under one or more contributor
7 * license agreements.
8 *
9 * This program is free software: you can redistribute it and/or modify it under
10 * the terms of the GNU Affero General Public License as published by the Free
11 * Software Foundation, either version 3 of the License, or (at your option) any
12 * later version.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
17 * details.
18 *
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see http://www.gnu.org/licenses/
21 */
22
23#pragma once
24
25//==========================================================
26// Includes.
27//
28
29#include <stddef.h>
30#include <stdint.h>
31
32#include "cf_mutex.h"
33#include "fault.h"
34
35
36//==========================================================
37// Typedefs & constants.
38//
39
40typedef struct vhash_s vhash;
41
42// DO NOT access this member data directly - use the API!
43// Caution - changing this struct could break warm or cool restart.
44typedef struct cf_vmapx_s {
45 // Vector-related.
46 uint32_t value_size;
47 uint32_t max_count;
48 volatile uint32_t count;
49
50 // Hash-related.
51 uint32_t key_size;
52 vhash* hash;
53
54 // Generic.
55 cf_mutex write_lock;
56
57 // Pad to 64 bytes.
58 uint8_t pad[36];
59
60 //<><><><><><><><><><><> 64 bytes <><><><><><><><><><><>
61
62 // Vector data.
63 uint8_t values[];
64} cf_vmapx;
65
66COMPILER_ASSERT(offsetof(cf_vmapx, values) == 64);
67
68typedef enum {
69 CF_VMAPX_OK = 0,
70 CF_VMAPX_ERR_BAD_PARAM,
71 CF_VMAPX_ERR_FULL,
72 CF_VMAPX_ERR_NAME_EXISTS,
73 CF_VMAPX_ERR_NAME_NOT_FOUND,
74 CF_VMAPX_ERR_UNKNOWN
75} cf_vmapx_err;
76
77
78//==========================================================
79// Public API.
80//
81
82size_t cf_vmapx_sizeof(uint32_t value_size, uint32_t max_count);
83
84void cf_vmapx_init(cf_vmapx* vmap, uint32_t value_size, uint32_t max_count, uint32_t hash_size, uint32_t max_name_size);
85void cf_vmapx_release(cf_vmapx* vmap);
86
87uint32_t cf_vmapx_count(const cf_vmapx* vmap);
88
89cf_vmapx_err cf_vmapx_get_by_index(const cf_vmapx* vmap, uint32_t index, void** pp_value);
90cf_vmapx_err cf_vmapx_get_by_name(const cf_vmapx* vmap, const char* name, void** pp_value);
91cf_vmapx_err cf_vmapx_get_by_name_w_len(const cf_vmapx* vmap, const char* name, size_t name_len, void** pp_value);
92
93cf_vmapx_err cf_vmapx_get_index(const cf_vmapx* vmap, const char* name, uint32_t* p_index);
94cf_vmapx_err cf_vmapx_get_index_w_len(const cf_vmapx* vmap, const char* name, size_t name_len, uint32_t* p_index);
95
96cf_vmapx_err cf_vmapx_put_unique(cf_vmapx* vmap, const char* name, uint32_t* p_index);
97cf_vmapx_err cf_vmapx_put_unique_w_len(cf_vmapx* vmap, const char* name, size_t name_len, uint32_t* p_index);
98
99
100//==========================================================
101// Private API - for enterprise separation only.
102//
103
104void* vmapx_value_ptr(const cf_vmapx* vmap, uint32_t index);
105
106vhash* vhash_create(uint32_t key_size, uint32_t n_rows);
107void vhash_destroy(vhash* h);
108void vhash_put(vhash* h, const char* key, size_t key_len, uint32_t value);
109