Initial VES for DANOS vRouter
[demo.git] / vnfs / VESreporting_vFW5.0_DANOS / evel / evel-library / code / evel_library / hashtable.h
1 #ifndef HASHTABLE_INCLUDED
2 #define HASHTABLE_INCLUDED
3
4 /*************************************************************************//**
5  *
6  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *        http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and 
17  * limitations under the License.
18  *
19  ****************************************************************************/
20
21 /**************************************************************************//**
22  * @file
23  * A simple hashtable.
24  *
25  * @note  No thread protection so you will need to use appropriate
26  * synchronization if use spans multiple threads.
27 *****************************************************************************/
28
29 typedef struct entry_s {
30         char *key;
31         void *value;
32         struct entry_s *next;
33 } ENTRY_T;
34
35 /**************************************************************************//**
36  * Hashtable structure
37  *****************************************************************************/
38
39 typedef struct hashtable_s {
40         size_t size;
41         struct entry_s **table; 
42 } HASHTABLE_T;
43
44 /**************************************************************************//**
45  * Hashtable initialization.
46  *
47  * Initialize the list supplied to be empty.
48  *
49  * @param   size  Size of hashtable
50
51  * @returns Hashtable pointer
52 ******************************************************************************/
53 /* Create a new hashtable. */
54 HASHTABLE_T *ht_create( size_t size );
55
56 /**************************************************************************//**
57  * Hash a string for a particular hash table.
58  *
59  * Initialize the list supplied to be empty.
60  *
61  * @param   hashtable    Pointer to the hashtable
62  * @param   key          String
63
64  * @returns hashvalue
65 ******************************************************************************/
66 size_t ht_hash( HASHTABLE_T *hashtable, char *key );
67
68 /**************************************************************************//**
69  * Create a key-value pair.
70  *
71  * @param   key     key string
72  * @param   value   value string
73  *
74  * @returns hashtable entry
75 ******************************************************************************/
76 ENTRY_T *ht_newpair( char *key, void *value );
77
78 /**************************************************************************//**
79  * Insert a key-value pair into a hash table.
80  *
81  * @param   key     key string
82  * @param   value   value string
83  *
84  * @returns Nothing
85 ******************************************************************************/
86 void ht_set( HASHTABLE_T *hashtable, char *key, void *value );
87
88 /**************************************************************************//**
89  *  Retrieve a key-value pair from a hash table.
90  *
91  * @param   key     key string
92  *
93  * @returns  value string
94 ******************************************************************************/
95 void *ht_get( HASHTABLE_T *hashtable, char *key );
96
97 #endif