3 * Written by Kern Sibbald, MMIV
8 Bacula® - The Network Backup Solution
10 Copyright (C) 2004-2006 Free Software Foundation Europe e.V.
12 The main author of Bacula is Kern Sibbald, with contributions from
13 many others, a complete list can be found in the file AUTHORS.
14 This program is Free Software; you can redistribute it and/or
15 modify it under the terms of version two of the GNU General Public
16 License as published by the Free Software Foundation plus additions
17 that are listed in the file LICENSE.
19 This program is distributed in the hope that it will be useful, but
20 WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 Bacula® is a registered trademark of John Walker.
30 The licensor of Bacula is the Free Software Foundation Europe
31 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
32 Switzerland, email:ftf@fsfeurope.org.
35 /* ========================================================================
37 * Hash table class -- htable
42 * Loop var through each member of table
44 #define foreach_htable(var, tbl) \
45 for((*((void **)&(var))=(void *)((tbl)->first())); \
47 (*((void **)&(var))=(void *)((tbl)->next())))
50 void *next; /* next hash item */
51 char *key; /* key this item */
52 uint32_t hash; /* hash for this key */
55 class htable : public SMARTALLOC {
56 hlink **table; /* hash table */
57 int loffset; /* link offset in item */
58 uint32_t num_items; /* current number of items */
59 uint32_t max_items; /* maximum items before growing */
60 uint32_t buckets; /* size of hash table */
61 uint32_t hash; /* temp storage */
62 uint32_t index; /* temp storage */
63 uint32_t mask; /* "remainder" mask */
64 uint32_t rshift; /* amount to shift down */
65 hlink *walkptr; /* table walk pointer */
66 uint32_t walk_index; /* table walk index */
67 void hash_index(char *key); /* produce hash key,index */
68 void grow_table(); /* grow the table */
70 htable(void *item, void *link, int tsize = 31);
71 ~htable() { destroy(); }
72 void init(void *item, void *link, int tsize = 31);
73 bool insert(char *key, void *item);
74 void *lookup(char *key);
75 void *first(); /* get first item in table */
76 void *next(); /* get next item in table */
78 void stats(); /* print stats about the table */
79 uint32_t size(); /* return size of table */