1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
19 /********************************************************************20**
21 Name: common hash functions
25 Desc: Structures, variables and typedefs required by common
27 (Newer version of functions in cm_bdy1)
31 *********************************************************************21*/
42 /* forward definitions */
44 typedef struct cmHashListCp CmHashListCp; /* hash list control point */
49 typedef S16 (* CmHashFunc) ARGS((CmHashListCp *hashListCp, U8 *key,
50 U16 keyLen, U16 *idx));
53 typedef struct cmListEnt CmListEnt; /* list entry */
55 struct cmListEnt /* list entry */
57 CmListEnt *next; /* next entry in list */
58 CmListEnt *prev; /* prev entry in list */
62 typedef struct cmListBinEnt CmListBinEnt;/* Bin entry */
64 struct cmListBinEnt /* Bin entry */
66 CmListEnt *next; /* next entry in list */
67 CmListEnt *prev; /* prev entry in list */
68 U16 nmbEnt; /* current number of entries */
75 typedef struct cmHashListEnt /* hash list entry */
77 CmListEnt list; /* list pointers */
78 U8 *key; /* pointer to key */
79 U16 keyLen; /* length of key */
80 U16 hashVal; /* computed hash value */
83 /* hash list control point */
85 struct cmHashListCp /* hash list control point */
87 #ifndef CM_MT_HASH_BIN
88 CmListEnt *hl; /* pointer to hash list bins */
90 CmListBinEnt *hl; /* pointer to hash list bins */
92 Region region; /* memory region to allocate bins */
93 Pool pool; /* memory pool to allocate bins */
94 U16 nmbBins; /* number of hash list bins */
95 U16 binBitMask; /* number of bits if nmbBins is power of 2 */
96 U8 nmbBinBits; /* number of bits to represent nmbBins */
97 #ifndef CM_MT_HASH_BIN
98 U16 nmbEnt; /* current number of entries */
100 U16 offset; /* offset of CmHashListEnt in entries */
101 Bool dupFlg; /* allow duplicate keys */
102 U16 keyType; /* key type for selecting hash functions */
103 CmHashFunc hashFunc; /* hash function for this key type */
107 /* functions prototypes */
109 EXTERN S16 cmHashListInit ARGS((
110 CmHashListCp *hashListCp, /* hash list to initialize */
111 U16 nmbBins, /* number of hash list bins */
112 U16 offset, /* offset of CmHashListEnt in entries */
113 Bool dupFlg, /* allow duplicate keys */
114 U16 keyType, /* key type for selecting hash fn */
115 Region region, /* memory region to allocate bins */
116 Pool pool)); /* memory pool to allocate bins */
118 EXTERN S16 cmHashListDeinit ARGS((
119 CmHashListCp *hashListCp));/* hash list to initialize */
121 EXTERN S16 cmHashListInsert ARGS((
122 CmHashListCp *hashListCp, /* hash list to add to */
123 PTR entry, /* entry to add */
124 U8 *key, /* pointer to key */
125 U16 keyLen)); /* length of key */
127 EXTERN S16 cmHashListDelete ARGS((
128 CmHashListCp *hashListCp, /* hash list to delete from */
129 PTR entry)); /* entry to delete */
131 EXTERN S16 cmHashListFind ARGS((
132 CmHashListCp *hashListCp, /* hash list to search */
133 U8 *key, /* pointer to key */
134 U16 keyLen, /* length of key */
135 U16 seqNmb, /* used in case of duplicate keys */
136 PTR *entry)); /* entry to be returned */
138 EXTERN S16 cmHashListGetNext ARGS((
139 CmHashListCp *hashListCp, /* hash list to get from */
140 PTR prevEnt, /* previous entry */
141 PTR *entry)); /* entry to be returned */
143 #ifdef CM_MT_HASH_BIN
144 EXTERN S16 cmHashListBinGetNextEntry ARGS((
145 CmHashListCp *hashListCp, /* hash list to get from */
146 U16 binIdx, /* Index of the bin */
147 PTR prevEnt, /* previous entry */
148 PTR *entry)); /* entry to be returned */
151 /* This function is obsoleted! Use macros defined in cm_hash.h instead
153 EXTERN S16 cmHashListQuery ARGS((
154 CmHashListCp *hashListCp, /* hash list to query */
155 U8 queryType, /* type of query */
156 U16 *result)); /* result of query */
158 /* Hash list with open addressing
160 EXTERN S16 cmHashListOAInsert ARGS((
161 CmHashListCp *hashListCp, /* hash list to add to */
162 PTR entry, /* entry to add */
163 U8 *key, /* pointer to key */
164 U16 keyLen)); /* length of key */
170 #endif /* __CMHASHX__ */
173 /********************************************************************30**
176 **********************************************************************/