1 mike 1.1 /*
2 **==============================================================================
3 **
4 ** Open Management Infrastructure (OMI)
5 **
6 ** Copyright (c) Microsoft Corporation
7 **
8 ** Licensed under the Apache License, Version 2.0 (the "License"); you may not
9 ** use this file except in compliance with the License. You may obtain a copy
10 ** of the License at
11 **
12 ** http://www.apache.org/licenses/LICENSE-2.0
13 **
14 ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
16 ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
17 ** MERCHANTABLITY OR NON-INFRINGEMENT.
18 **
19 ** See the Apache 2 License for the specific language governing permissions
20 ** and limitations under the License.
21 **
22 mike 1.1 **==============================================================================
23 */
24
25 #ifndef _base_hashtable_h
26 #define _base_hashtable_h
27
28 #include "config.h"
29 #include <common.h>
30
31 BEGIN_EXTERNC
32
33 typedef struct _HashBucket
34 {
35 struct _HashBucket* next;
36 }
37 HashBucket;
38
39 typedef struct _HashTable
40 {
41 /* Array of poitners to hash lists */
42 HashBucket** lists;
43 mike 1.1 size_t numLists;
44
45 /* User-defined hash function */
46 size_t (*hash)(const HashBucket* bucket);
47
48 /* User-defined euqal function (returns non-zeroif equal) */
49 int (*equal)(const HashBucket* bucket, const HashBucket* bucket2);
50
51 /* User-defined function to release a hash bucket */
52 void (*release)(HashBucket* bucket);
53 }
54 HashTable;
55
56 int HashTable_Init(
57 HashTable* self,
58 size_t numLists,
59 size_t (*hash)(const HashBucket* bucket),
60 int (*equal)(const HashBucket* bucket1, const HashBucket* bucket2),
61 void (*release)(HashBucket* bucket));
62
63 void HashTable_Destroy(
64 mike 1.1 HashTable* self);
65
66 HashBucket* HashTable_Find(
67 HashTable* self,
68 const HashBucket* keyBucket);
69
70 int HashTable_Insert(
71 HashTable* self,
72 HashBucket* bucket);
73
74 int HashTable_Remove(
75 HashTable* self,
76 const HashBucket* keyBucket);
77
78 unsigned int HashString(const char* str);
79
80 END_EXTERNC
81
82 #endif /* _base_hashtable_h */
|