2 Bacula® - The Network Backup Solution
4 Copyright (C) 2004-2008 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version two of the GNU General Public
10 License as published by the Free Software Foundation and included
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 Bacula® is a registered trademark of John Walker.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
30 * Written by Kern Sibbald, MMIV
35 /* ========================================================================
37 * Hash table class -- htable
42 * BIG_MALLOC is to provide a large malloc service to htable
47 * Loop var through each member of table
50 #define foreach_htable(var, tbl) \
51 for((var)=(typeof(var))((tbl)->first()); \
53 (var)=(typeof(var))((tbl)->next()))
55 #define foreach_htable(var, tbl) \
56 for((*((void **)&(var))=(void *)((tbl)->first())); \
58 (*((void **)&(var))=(void *)((tbl)->next())))
64 void *next; /* next hash item */
65 char *key; /* key this item */
66 uint32_t hash; /* hash for this key */
70 struct h_mem *next; /* next buffer */
71 int rem; /* remaining bytes */
72 char *mem; /* memory pointer */
73 char first[1]; /* first byte */
76 class htable : public SMARTALLOC {
77 hlink **table; /* hash table */
78 int loffset; /* link offset in item */
79 uint32_t num_items; /* current number of items */
80 uint32_t max_items; /* maximum items before growing */
81 uint32_t buckets; /* size of hash table */
82 uint32_t hash; /* temp storage */
83 uint32_t index; /* temp storage */
84 uint32_t mask; /* "remainder" mask */
85 uint32_t rshift; /* amount to shift down */
86 hlink *walkptr; /* table walk pointer */
87 uint32_t walk_index; /* table walk index */
88 uint32_t total_size; /* total bytes malloced */
89 uint32_t blocks; /* blocks malloced */
91 struct h_mem *mem; /* malloced memory blocks */
92 void malloc_buf(int size); /* Get a bit buffer */
94 void hash_index(char *key); /* produce hash key,index */
95 void grow_table(); /* grow the table */
98 htable(void *item, void *link, int tsize = 31);
99 ~htable() { destroy(); }
100 void init(void *item, void *link, int tsize = 31);
101 bool insert(char *key, void *item);
102 void *lookup(char *key);
103 void *first(); /* get first item in table */
104 void *next(); /* get next item in table */
106 void stats(); /* print stats about the table */
107 uint32_t size(); /* return size of table */
108 char *hash_malloc(int size); /* malloc bytes for a hash entry */
110 void hash_free(); /* free all hash allocated bytes */