Added tdb_get/set_int_byblob, which takes a size_t len and then implemented
[kai/samba.git] / source3 / include / hash.h
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 2.0
4
5    Copyright (C) Ying Chen 2000.
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (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 General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #ifndef _HASH_H_
23 #define _HASH_H_
24
25 #define MAX_HASH_TABLE_SIZE    32768
26 #define HASH_TABLE_INCREMENT  2
27
28 typedef int (*compare_function)(char *, char *);
29 typedef int (*hash_function)(int, char *);
30
31 /*
32  * lru_link: links the node to the LRU list.
33  * hash_elem: the pointer to the element that is tied onto the link.
34  */
35 typedef struct lru_node {
36         ubi_dlNode lru_link;
37         void *hash_elem;
38 } lru_node;
39
40 /* 
41  * bucket_link: link the hash element to the bucket chain that it belongs to.
42  * lru_link: this element ties the hash element to the lru list. 
43  * bucket: a pointer to the hash bucket that this element belongs to.
44  * value: a pointer to the hash element content. It can be anything.
45  * key: stores the string key. The hash_element is always allocated with
46  * more memory space than the structure shown below to accomodate the space
47  * used for the whole string. But the memory is always appended at the 
48  * end of the structure, so keep "key" at the end of the structure.
49  * Don't move it.
50  */
51 typedef struct hash_element {
52         ubi_dlNode      bucket_link;          
53         lru_node    lru_link;
54         ubi_dlList      *bucket;
55         void    *value;         
56         char key[1];    
57 } hash_element;
58
59 /*
60  * buckets: a list of buckets, implemented as a dLinkList. 
61  * lru_chain: the lru list of all the hash elements. 
62  * num_elements: the # of elements in the hash table.
63  * size: the hash table size.
64  * comp_func: the compare function used during hash key comparisons.
65  */
66
67 typedef struct hash_table {
68         ubi_dlList      *buckets;
69         ubi_dlList      lru_chain;     
70         int     num_elements;   
71         int     size;
72         compare_function        comp_func; 
73 } hash_table;
74
75 #endif /* _HASH_H_ */