1 #ifndef HASHTABLE_INCLUDED
2 #define HASHTABLE_INCLUDED
4 /*************************************************************************//**
6 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
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
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.
19 ****************************************************************************/
21 /**************************************************************************//**
25 * @note No thread protection so you will need to use appropriate
26 * synchronization if use spans multiple threads.
27 *****************************************************************************/
29 typedef struct entry_s {
35 /**************************************************************************//**
37 *****************************************************************************/
39 typedef struct hashtable_s {
41 struct entry_s **table;
44 /**************************************************************************//**
45 * Hashtable initialization.
47 * Initialize the list supplied to be empty.
49 * @param size Size of hashtable
51 * @returns Hashtable pointer
52 ******************************************************************************/
53 /* Create a new hashtable. */
54 HASHTABLE_T *ht_create( size_t size );
56 /**************************************************************************//**
57 * Hash a string for a particular hash table.
59 * Initialize the list supplied to be empty.
61 * @param hashtable Pointer to the hashtable
65 ******************************************************************************/
66 size_t ht_hash( HASHTABLE_T *hashtable, char *key );
68 /**************************************************************************//**
69 * Create a key-value pair.
71 * @param key key string
72 * @param value value string
74 * @returns hashtable entry
75 ******************************************************************************/
76 ENTRY_T *ht_newpair( char *key, void *value );
78 /**************************************************************************//**
79 * Insert a key-value pair into a hash table.
81 * @param key key string
82 * @param value value string
85 ******************************************************************************/
86 void ht_set( HASHTABLE_T *hashtable, char *key, void *value );
88 /**************************************************************************//**
89 * Retrieve a key-value pair from a hash table.
91 * @param key key string
93 * @returns value string
94 ******************************************************************************/
95 void *ht_get( HASHTABLE_T *hashtable, char *key );