libghthash 0.6.0
ght_hash_table.h
Go to the documentation of this file.
1/*-*-c-*- ************************************************************
2 * Copyright (C) 2001-2005, Simon Kagstrom
3 *
4 * Filename: ght_hash_table.h.in
5 * Description: The definitions used in the hash table.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
21 *
22 * $Id: ght_hash_table.h.in 15761 2007-07-15 06:08:52Z ska $
23 *
24 ********************************************************************/
25
59#ifndef GHT_HASH_TABLE_H
60#define GHT_HASH_TABLE_H
61
62#include <stdlib.h> /* size_t */
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68#define GHT_HEURISTICS_NONE 0
69#define GHT_HEURISTICS_TRANSPOSE 1
70#define GHT_HEURISTICS_MOVE_TO_FRONT 2
71#define GHT_AUTOMATIC_REHASH 4
72
73#ifndef TRUE
74#define TRUE 1
75#endif
76
77#ifndef FALSE
78#define FALSE 0
79#endif
80
82typedef unsigned int ght_uint32_t;
83
88typedef struct s_hash_key
89{
90 unsigned int i_size;
91 const void *p_key;
93
94/*
95 * The structure for hash entries.
96 *
97 * LOCK: Should be possible to do somewhat atomically
98 */
99typedef struct s_hash_entry
100{
101 void *p_data;
102
103 struct s_hash_entry *p_next;
104 struct s_hash_entry *p_prev;
105 struct s_hash_entry *p_older;
106 struct s_hash_entry *p_newer;
107 ght_hash_key_t key;
108
109} ght_hash_entry_t;
110
111/*
112 * The structure used in iterations. You should not care about the
113 * contents of this, it will be filled and updated by ght_first() and
114 * ght_next().
115 */
116typedef struct
117{
118 ght_hash_entry_t *p_entry; /* The current entry */
119 ght_hash_entry_t *p_next; /* The next entry */
121
136
147typedef void *(*ght_fn_alloc_t)(size_t size);
148
155typedef void (*ght_fn_free_t)(void *ptr);
156
164typedef void (*ght_fn_bucket_free_callback_t)(void *data, const void *key);
165
169typedef struct
170{
171 unsigned int i_items;
172 unsigned int i_size;
179
180 /* private: */
181 ght_hash_entry_t **pp_entries;
182 int *p_nr; /* The number of entries in each bucket */
183 int i_size_mask; /* The number of bits used in the size */
184 unsigned int bucket_limit;
185
186 ght_hash_entry_t *p_oldest; /* The entry inserted the earliest. */
187 ght_hash_entry_t *p_newest; /* The entry inserted the latest. */
189
209ght_hash_table_t *ght_create(unsigned int i_size);
210
233
245
261void ght_set_heuristics(ght_hash_table_t *p_ht, int i_heuristics);
262
277void ght_set_rehash(ght_hash_table_t *p_ht, int b_rehash);
278
300
301
309unsigned int ght_size(ght_hash_table_t *p_ht);
310
319
320
356 void *p_entry_data,
357 unsigned int i_key_size, const void *p_key_data);
358
373 void *p_entry_data,
374 unsigned int i_key_size, const void *p_key_data);
375
376
388 unsigned int i_key_size, const void *p_key_data);
389
401 unsigned int i_key_size, const void *p_key_data);
402
444void *ght_first(ght_hash_table_t *p_ht, ght_iterator_t *p_iterator, const void **pp_key);
445
467
468void *ght_first_keysize(ght_hash_table_t *p_ht, ght_iterator_t *p_iterator, const void **pp_key, unsigned int *size);
469
489void *ght_next(ght_hash_table_t *p_ht, ght_iterator_t *p_iterator, const void **pp_key);
490
513
514void *ght_next_keysize(ght_hash_table_t *p_ht, ght_iterator_t *p_iterator, const void **pp_key, unsigned int *size);
515
532void ght_rehash(ght_hash_table_t *p_ht, unsigned int i_size);
533
557
558/* exported hash functions */
559
573
585
597
598#ifdef USE_PROFILING
603void ght_print(ght_hash_table_t *p_ht);
604#endif
605
606#ifdef __cplusplus
607}
608#endif
609
610#endif /* GHT_HASH_TABLE_H */
ght_uint32_t(*) ght_fn_hash_t(ght_hash_key_t *p_key)
Definition ght_hash_table.h:135
void * ght_first_keysize(ght_hash_table_t *p_ht, ght_iterator_t *p_iterator, const void **pp_key, unsigned int *size)
void * ght_next(ght_hash_table_t *p_ht, ght_iterator_t *p_iterator, const void **pp_key)
void ght_set_hash(ght_hash_table_t *p_ht, ght_fn_hash_t fn_hash)
struct s_hash_key ght_hash_key_t
unsigned int ght_size(ght_hash_table_t *p_ht)
void * ght_replace(ght_hash_table_t *p_ht, void *p_entry_data, unsigned int i_key_size, const void *p_key_data)
void * ght_first(ght_hash_table_t *p_ht, ght_iterator_t *p_iterator, const void **pp_key)
void ght_finalize(ght_hash_table_t *p_ht)
void * ght_next_keysize(ght_hash_table_t *p_ht, ght_iterator_t *p_iterator, const void **pp_key, unsigned int *size)
ght_uint32_t ght_rotating_hash(ght_hash_key_t *p_key)
void ght_set_heuristics(ght_hash_table_t *p_ht, int i_heuristics)
void ght_rehash(ght_hash_table_t *p_ht, unsigned int i_size)
void ght_set_alloc(ght_hash_table_t *p_ht, ght_fn_alloc_t fn_alloc, ght_fn_free_t fn_free)
unsigned int ght_uint32_t
Definition ght_hash_table.h:82
void(*) ght_fn_free_t(void *ptr)
Definition ght_hash_table.h:155
ght_uint32_t ght_crc_hash(ght_hash_key_t *p_key)
ght_uint32_t ght_one_at_a_time_hash(ght_hash_key_t *p_key)
int ght_insert(ght_hash_table_t *p_ht, void *p_entry_data, unsigned int i_key_size, const void *p_key_data)
void ght_set_rehash(ght_hash_table_t *p_ht, int b_rehash)
void(*) ght_fn_bucket_free_callback_t(void *data, const void *key)
Definition ght_hash_table.h:164
void * ght_remove(ght_hash_table_t *p_ht, unsigned int i_key_size, const void *p_key_data)
void ght_set_bounded_buckets(ght_hash_table_t *p_ht, unsigned int limit, ght_fn_bucket_free_callback_t fn)
unsigned int ght_table_size(ght_hash_table_t *p_ht)
ght_hash_table_t * ght_create(unsigned int i_size)
void * ght_get(ght_hash_table_t *p_ht, unsigned int i_key_size, const void *p_key_data)
void *(*) ght_fn_alloc_t(size_t size)
Definition ght_hash_table.h:147
Definition ght_hash_table.h:170
unsigned int i_items
Definition ght_hash_table.h:171
int i_heuristics
Definition ght_hash_table.h:177
unsigned int i_size
Definition ght_hash_table.h:172
ght_fn_alloc_t fn_alloc
Definition ght_hash_table.h:174
ght_fn_hash_t fn_hash
Definition ght_hash_table.h:173
ght_fn_bucket_free_callback_t fn_bucket_free
Definition ght_hash_table.h:176
ght_fn_free_t fn_free
Definition ght_hash_table.h:175
int i_automatic_rehash
Definition ght_hash_table.h:178
Definition ght_hash_table.h:117
Definition ght_hash_table.h:100
Definition ght_hash_table.h:89
const void * p_key
Definition ght_hash_table.h:91
unsigned int i_size
Definition ght_hash_table.h:90