nemea-common 1.6.3
cuckoo_hash.h
Go to the documentation of this file.
1
8/*
9 * Copyright (C) 2013,2014 CESNET
10 *
11 * LICENSE TERMS
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in
20 * the documentation and/or other materials provided with the
21 * distribution.
22 * 3. Neither the name of the Company nor the names of its contributors
23 * may be used to endorse or promote products derived from this
24 * software without specific prior written permission.
25 *
26 * ALTERNATIVELY, provided that this notice is retained in full, this
27 * product may be distributed under the terms of the GNU General Public
28 * License (GPL) version 2 or later, in which case the provisions
29 * of the GPL apply INSTEAD OF those given above.
30 *
31 * This software is provided ``as is'', and any express or implied
32 * warranties, including, but not limited to, the implied warranties of
33 * merchantability and fitness for a particular purpose are disclaimed.
34 * In no event shall the company or contributors be liable for any
35 * direct, indirect, incidental, special, exemplary, or consequential
36 * damages (including, but not limited to, procurement of substitute
37 * goods or services; loss of use, data, or profits; or business
38 * interruption) however caused and on any theory of liability, whether
39 * in contract, strict liability, or tort (including negligence or
40 * otherwise) arising in any way out of the use of this software, even
41 * if advised of the possibility of such damage.
42 *
43 */
44
45#ifndef CUCKOO_HASH_H
46#define CUCKOO_HASH_H
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
55#define REHASH_FAILURE -1
56
60#define NOT_FOUND -1
61
65#define INSERT_FAILURE -2
66
71#define REHASH_ENABLE 1
72
77#define REHASH_DISABLE 0
78
82typedef struct {
84 char *key;
85 unsigned int key_length;
86 void *data;
88} cc_item_t;
89
93typedef struct {
96 unsigned int data_size;
97 unsigned int table_size;
98 unsigned int key_length;
99 unsigned int rehash;
100 unsigned int item_count;
103/*
104 * Initialization function for the table.
105 */
106int ht_init(cc_hash_table_t* new_table, unsigned int table_size, unsigned int data_size, unsigned int key_length, int rehash);
107
108/*
109 * Function for resizing and rehashing the table.
110 */
112
113/*
114 * Function for inserting an element.
115 */
116int ht_insert(cc_hash_table_t* ht, char *key, const void *new_data, unsigned int n_key_length);
117
118/*
119 * Function for checking whether the table is empty.
120 */
122
123/*
124 * Getters for data/index to item in table.
125 */
126void *ht_get(cc_hash_table_t* ht, char* key, unsigned int key_length);
127int ht_get_index(cc_hash_table_t* ht, char* key, unsigned int key_length);
128
129/*
130 * Procedures for removing single item from table.
131 */
132void ht_remove_by_key(cc_hash_table_t* ht, char* key, unsigned int key_length);
133void ht_remove_by_index(cc_hash_table_t* ht, unsigned int index);
134
135/*
136 * Procedure for removing all items from table.
137 */
139
140/*
141 * Destructor of the table.
142 */
144
145#ifdef __cplusplus
146}
147#endif
148
149#endif
void ht_remove_by_index(cc_hash_table_t *ht, unsigned int index)
void * ht_get(cc_hash_table_t *ht, char *key, unsigned int key_length)
int rehash(cc_hash_table_t *ht, cc_item_t *rest)
int ht_get_index(cc_hash_table_t *ht, char *key, unsigned int key_length)
int ht_init(cc_hash_table_t *new_table, unsigned int table_size, unsigned int data_size, unsigned int key_length, int rehash)
int ht_insert(cc_hash_table_t *ht, char *key, const void *new_data, unsigned int n_key_length)
int ht_is_empty(cc_hash_table_t *ht)
void ht_clear(cc_hash_table_t *ht)
void ht_remove_by_key(cc_hash_table_t *ht, char *key, unsigned int key_length)
void ht_destroy(cc_hash_table_t *ht)
unsigned int table_size
Definition cuckoo_hash.h:97
unsigned int key_length
Definition cuckoo_hash.h:98
unsigned int rehash
Definition cuckoo_hash.h:99
unsigned int item_count
cc_item_t * table
Definition cuckoo_hash.h:95
unsigned int data_size
Definition cuckoo_hash.h:96
unsigned int key_length
Definition cuckoo_hash.h:85
char * key
Definition cuckoo_hash.h:84
void * data
Definition cuckoo_hash.h:86