ROHC compression/decompression library
hashtable.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Viveris Technologies
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 /**
20  * @file hashtable.h
21  * @brief Efficient, secure hash table
22  * @author Didier Barvaux <didier.barvaux@toulouse.viveris.com>
23  */
24 
25 #ifndef ROHC_HASHTABLE_H
26 #define ROHC_HASHTABLE_H
27 
28 #include <stddef.h>
29 #include <stdbool.h>
30 #include <stdint.h>
31 
32 
33 /** A linked list */
34 struct hashlist
35 {
36  struct hashlist *prev;
37  struct hashlist *next;
38  struct hashlist *prev_cr;
39  struct hashlist *next_cr;
40  uint8_t key[];
41 } __attribute__((packed));
42 
43 
44 /** One hash table */
45 struct hashtable
46 {
47  size_t key_len;
48  size_t full_key_len;
49  uint64_t mask;
50  struct hashlist **table;
51  char key[16];
52 };
53 
54 
55 bool hashtable_new(struct hashtable *const hashtable,
56  const size_t key_len,
57  const size_t size)
58  __attribute((warn_unused_result, nonnull(1)));
59 
60 void hashtable_free(struct hashtable *const hashtable)
61  __attribute((nonnull(1)));
62 
63 void hashtable_add(struct hashtable *const hashtable,
64  const void *const key,
65  void *const elem)
66  __attribute((nonnull(1, 2, 3)));
67 
68 void * hashtable_get(const struct hashtable *const hashtable,
69  const void *const key)
70  __attribute((warn_unused_result, nonnull(1, 2)));
71 
72 void hashtable_del(struct hashtable *const hashtable,
73  const void *const key)
74  __attribute((nonnull(1, 2)));
75 
76 #endif
77 
struct hashlist * prev_cr
Definition: hashtable.h:38
uint8_t key[]
Definition: hashtable.h:40
struct hashlist ** table
Definition: hashtable.h:50
size_t full_key_len
Definition: hashtable.h:48
bool hashtable_new(struct hashtable *const hashtable, const size_t key_len, const size_t size) __attribute((warn_unused_result
struct hashlist * next
Definition: hashtable.h:37
void hashtable_del(struct hashtable *const hashtable, const void *const key) __attribute((nonnull(1
void hashtable_free(struct hashtable *const hashtable) __attribute((nonnull(1)))
Definition: hashtable.c:52
void hashtable_add(struct hashtable *const hashtable, const void *const key, void *const elem) __attribute((nonnull(1
bool nonnull(1)))
void void * hashtable_get(const struct hashtable *const hashtable, const void *const key) __attribute((warn_unused_result
size_t key_len
Definition: hashtable.h:47
char key[16]
Definition: hashtable.h:51
uint64_t mask
Definition: hashtable.h:49
Definition: hashtable.h:34
struct hashlist * next_cr
Definition: hashtable.h:39
Definition: hashtable.h:45
struct hashlist * prev
Definition: hashtable.h:36