1 /*
2 * Copyright (C) 2018 Alexander Borisov
3 *
4 * Author: Alexander Borisov <borisov@lexbor.com>
5 */
6
7 #ifndef LEXBOR_SHS_H
8 #define LEXBOR_SHS_H
9
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13
14 #include <string.h>
15
16 #include "lexbor/core/base.h"
17
18
19 typedef struct {
20 char *key;
21 void *value;
22
23 size_t key_len;
24 size_t next;
25 }
26 lexbor_shs_entry_t;
27
28 typedef struct {
29 uint32_t key;
30 uint32_t value;
31
32 uint32_t next;
33 }
34 lexbor_shs_hash_t;
35
36
37 LXB_API const lexbor_shs_entry_t *
38 lexbor_shs_entry_get_static(const lexbor_shs_entry_t *tree,
39 const lxb_char_t *key, size_t size);
40
41 LXB_API const lexbor_shs_entry_t *
42 lexbor_shs_entry_get_lower_static(const lexbor_shs_entry_t *root,
43 const lxb_char_t *key, size_t key_len);
44
45 LXB_API const lexbor_shs_entry_t *
46 lexbor_shs_entry_get_upper_static(const lexbor_shs_entry_t *root,
47 const lxb_char_t *key, size_t key_len);
48
49 /*
50 * Inline functions
51 */
52 lxb_inline const lexbor_shs_hash_t *
lexbor_shs_hash_get_static(const lexbor_shs_hash_t * table,const size_t table_size,const uint32_t key)53 lexbor_shs_hash_get_static(const lexbor_shs_hash_t *table,
54 const size_t table_size, const uint32_t key)
55 {
56 const lexbor_shs_hash_t *entry;
57
58 entry = &table[ (key % table_size) + 1 ];
59
60 do {
61 if (entry->key == key) {
62 return entry;
63 }
64
65 entry = &table[entry->next];
66 }
67 while (entry != table);
68
69 return NULL;
70 }
71
72
73 #ifdef __cplusplus
74 } /* extern "C" */
75 #endif
76
77 #endif /* LEXBOR_SHS_H */
78
79
80
81
82
83