RTS API Documentation
1.10.11
src
include
private
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
;
24
hashtable_flag_t
flags
;
25
hashtable_destructor_t
destructor
;
26
struct
entry
*
next
;
27
};
28
29
struct
switch_hashtable_iterator
{
30
unsigned
int
pos
;
31
struct
entry
*
e
;
32
struct
switch_hashtable
*
h
;
33
};
34
35
struct
switch_hashtable
{
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
49
hash
(
switch_hashtable_t
*
h
,
void
*
k
)
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
*/
entry::h
unsigned int h
Definition:
switch_hashtable_private.h:23
switch_hashtable_iterator::h
struct switch_hashtable * h
Definition:
switch_hashtable_private.h:32
switch_hashtable::loadlimit
unsigned int loadlimit
Definition:
switch_hashtable_private.h:39
hashtable_destructor_t
void(* hashtable_destructor_t)(void *ptr)
Definition:
switch_types.h:2375
indexFor
static __inline__ unsigned int indexFor(unsigned int tablelength, unsigned int hashvalue)
Definition:
switch_hashtable_private.h:65
switch_hashtable::table
struct entry ** table
Definition:
switch_hashtable_private.h:37
entry::v
void * v
Definition:
switch_hashtable_private.h:22
hash
static unsigned int hash(switch_hashtable_t *h, void *k)
Definition:
switch_hashtable_private.h:49
switch_hashtable::primeindex
unsigned int primeindex
Definition:
switch_hashtable_private.h:40
entry::k
void * k
Definition:
switch_hashtable_private.h:22
hashtable_flag_t
hashtable_flag_t
Definition:
switch_hashtable.h:119
switch_hashtable
Definition:
switch_hashtable_private.h:35
entry::flags
hashtable_flag_t flags
Definition:
switch_hashtable_private.h:24
switch_hashtable_iterator::pos
unsigned int pos
Definition:
switch_hashtable_private.h:30
switch_hashtable_iterator
Definition:
switch_hashtable_private.h:29
switch_hashtable::entrycount
unsigned int entrycount
Definition:
switch_hashtable_private.h:38
switch_hashtable::hashfn
unsigned int(* hashfn)(void *k)
Definition:
switch_hashtable_private.h:41
switch_hashtable::tablelength
unsigned int tablelength
Definition:
switch_hashtable_private.h:36
entry
Definition:
switch_hashtable_private.h:20
switch_hashtable_iterator::e
struct entry * e
Definition:
switch_hashtable_private.h:31
switch_hashtable.h
entry::destructor
hashtable_destructor_t destructor
Definition:
switch_hashtable_private.h:25
entry::next
struct entry * next
Definition:
switch_hashtable_private.h:26
Generated by
1.8.13