2 Bacula® - The Network Backup Solution
4 Copyright (C) 2004-2011 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 three of the GNU Affero 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 Affero 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 Kern Sibbald.
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.
29 * Written by Kern Sibbald, MMIV
35 /* ========================================================================
37 * Hash table class -- htable
42 * Loop var through each member of table
45 #define foreach_htable(var, tbl) \
46 for((var)=(typeof(var))((tbl)->first()); \
48 (var)=(typeof(var))((tbl)->next()))
50 #define foreach_htable(var, tbl) \
51 for((*((void **)&(var))=(void *)((tbl)->first())); \
53 (*((void **)&(var))=(void *)((tbl)->next())))
69 void *next; /* next hash item */
70 key_type_t key_type; /* type of key used to hash */
71 union hlink_key key; /* key for this item */
72 uint64_t hash; /* hash for this key */
76 struct h_mem *next; /* next buffer */
77 int32_t rem; /* remaining bytes in big_buffer */
78 char *mem; /* memory pointer */
79 char first[1]; /* first byte */
82 class htable : public SMARTALLOC {
83 hlink **table; /* hash table */
84 int loffset; /* link offset in item */
85 hlink *walkptr; /* table walk pointer */
86 uint64_t hash; /* temp storage */
87 uint64_t total_size; /* total bytes malloced */
88 uint32_t walk_index; /* table walk index */
89 uint32_t num_items; /* current number of items */
90 uint32_t max_items; /* maximum items before growing */
91 uint32_t buckets; /* size of hash table */
92 uint32_t index; /* temp storage */
93 uint32_t mask; /* "remainder" mask */
94 uint32_t rshift; /* amount to shift down */
95 uint32_t blocks; /* blocks malloced */
96 struct h_mem *mem_block; /* malloc'ed memory block chain */
97 void malloc_big_buf(int size); /* Get a big buffer */
98 void hash_index(char *key); /* produce hash key,index */
99 void hash_index(uint32_t key); /* produce hash key,index */
100 void hash_index(uint64_t key); /* produce hash key,index */
101 void grow_table(); /* grow the table */
104 htable(void *item, void *link, int tsize = 31);
105 ~htable() { destroy(); }
106 void init(void *item, void *link, int tsize = 31);
107 bool insert(char *key, void *item);
108 bool insert(uint32_t key, void *item);
109 bool insert(uint64_t key, void *item);
110 void *lookup(char *key);
111 void *lookup(uint32_t key);
112 void *lookup(uint64_t key);
113 void *first(); /* get first item in table */
114 void *next(); /* get next item in table */
116 void stats(); /* print stats about the table */
117 uint32_t size(); /* return size of table */
118 char *hash_malloc(int size); /* malloc bytes for a hash entry */
119 void hash_big_free(); /* free all hash allocated big buffers */
122 #endif /* HTABLE_H */