FreeSWITCH API Documentation  1.7.0
switch_hashtable_private.h
Go to the documentation of this file.
1 /*
2  * FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
3  *
4  * switch_hashtable_private.h -- Hashtable
5  *
6  */
7 
8 /* hashtable_private.h -- Copyright (C) 2002, 2004 Christopher Clark <firstname.lastname@cl.cam.ac.uk> */
9 
10 #ifndef __HASHTABLE_PRIVATE_CWC22_H__
11 #define __HASHTABLE_PRIVATE_CWC22_H__
12 
13 #include "switch_hashtable.h"
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 /*****************************************************************************/
19 
20 struct entry
21 {
22  void *k, *v;
23  unsigned int h;
26  struct entry *next;
27 };
28 
30  unsigned int pos;
31  struct entry *e;
33 };
34 
36  unsigned int tablelength;
37  struct entry **table;
38  unsigned int entrycount;
39  unsigned int loadlimit;
40  unsigned int primeindex;
41  unsigned int (*hashfn) (void *k);
42  int (*eqfn) (void *k1, void *k2);
43 };
44 
45 /*****************************************************************************/
46 
47 /*****************************************************************************/
48 static inline unsigned int
50 {
51  /* Aim to protect against poor hash functions by adding logic here
52  * - logic taken from java 1.4 hashtable source */
53  unsigned int i = h->hashfn(k);
54  i += ~(i << 9);
55  i ^= ((i >> 14) | (i << 18)); /* >>> */
56  i += (i << 4);
57  i ^= ((i >> 10) | (i << 22)); /* >>> */
58  return i;
59 }
60 
61 
62 /*****************************************************************************/
63 /* indexFor */
64 static __inline__ unsigned int
65 indexFor(unsigned int tablelength, unsigned int hashvalue) {
66  return (hashvalue % tablelength);
67 }
68 
69 /* Only works if tablelength == 2^N */
70 /*static inline unsigned int
71  indexFor(unsigned int tablelength, unsigned int hashvalue)
72  {
73  return (hashvalue & (tablelength - 1u));
74  }
75 */
76 
77 /*****************************************************************************/
78 #define freekey(X) free(X)
79 /*define freekey(X) ; */
80 
81 #ifdef __cplusplus
82 }
83 #endif
84 
85 /*****************************************************************************/
86 
87 #endif /* __HASHTABLE_PRIVATE_CWC22_H__*/
88 
89 /*
90  * Copyright (c) 2002, Christopher Clark
91  * All rights reserved.
92  *
93  * Redistribution and use in source and binary forms, with or without
94  * modification, are permitted provided that the following conditions
95  * are met:
96  *
97  * * Redistributions of source code must retain the above copyright
98  * notice, this list of conditions and the following disclaimer.
99  *
100  * * Redistributions in binary form must reproduce the above copyright
101  * notice, this list of conditions and the following disclaimer in the
102  * documentation and/or other materials provided with the distribution.
103  *
104  * * Neither the name of the original author; nor the names of any contributors
105  * may be used to endorse or promote products derived from this software
106  * without specific prior written permission.
107  *
108  *
109  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
110  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
111  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
112  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
113  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
114  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
115  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
116  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
117  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
118  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
119  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
120  */
121 /* For Emacs:
122  * Local Variables:
123  * mode:c
124  * indent-tabs-mode:t
125  * tab-width:4
126  * c-basic-offset:4
127  * End:
128  * For VIM:
129  * vim:set softtabstop=4 shiftwidth=4 tabstop=4 noet:
130  */
unsigned int h
struct switch_hashtable * h
static __inline__ unsigned int indexFor(unsigned int tablelength, unsigned int hashvalue)
unsigned int(* hashfn)(void *k)
static unsigned int hash(switch_hashtable_t *h, void *k)
hashtable_flag_t
hashtable_flag_t flags
int(* eqfn)(void *k1, void *k2)
hashtable_destructor_t destructor
void(* hashtable_destructor_t)(void *ptr)
struct entry * next