* Removed all Id tags.
[cacao.git] / src / toolbox / hashtable.h
1 /* src/toolbox/hashtable.h - functions for internal hashtables
2
3    Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25    Contact: cacao@cacaojvm.org
26
27    Authors: Reinhard Grafl
28             Christian Thalinger
29
30 */
31
32
33 #ifndef _HASHTABLE_H
34 #define _HASHTABLE_H
35
36 /* forward typedefs ***********************************************************/
37
38 typedef struct hashtable hashtable;
39
40
41 #include "config.h"
42 #include "vm/types.h"
43
44 #include "vm/global.h"
45 #include "vmcore/utf8.h"
46
47
48 /* data structures for hashtables ********************************************
49
50    All utf-symbols, javastrings and classes are stored in global
51    hashtables, so every symbol exists only once. Equal symbols have
52    identical pointers.  The functions for adding hashtable elements
53    search the table for the element with the specified name/text and
54    return it on success. Otherwise a new hashtable element is created.
55
56    The hashtables use external linking for handling collisions. The
57    hashtable structure contains a pointer <ptr> to the array of
58    hashtable slots. The number of hashtable slots and therefore the
59    size of this array is specified by the element <size> of hashtable
60    structure. <entries> contains the number of all hashtable elements
61    stored in the table, including those in the external chains.  The
62    hashtable element structures (utf, literalstring, classinfo)
63    contain both a pointer to the next hashtable element as a link for
64    the external hash chain and the key of the element. The key is
65    computed from the text of the string or the classname by using up
66    to 8 characters.
67         
68    If the number of entries in the hashtable exceeds twice the size of
69    the hashtableslot-array it is supposed that the average length of
70    the external chains has reached a value beyond 2. Therefore the
71    functions for adding hashtable elements (utf_new, class_new,
72    literalstring_new) double the hashtableslot-array. In this
73    restructuring process all elements have to be inserted into the new
74    hashtable and new external chains must be built.
75
76    Example for the layout of a hashtable:
77
78 hashtable.ptr-->+-------------------+
79                 |                   |
80                          ...
81                 |                   |
82                 +-------------------+   +-------------------+   +-------------------+
83                 | hashtable element |-->| hashtable element |-->| hashtable element |-->NULL
84                 +-------------------+   +-------------------+   +-------------------+
85                 | hashtable element |
86                 +-------------------+   +-------------------+   
87                 | hashtable element |-->| hashtable element |-->NULL
88                 +-------------------+   +-------------------+   
89                 | hashtable element |-->NULL
90                 +-------------------+
91                 |                   |
92                          ...
93                 |                   |
94                 +-------------------+
95
96 */
97
98
99 /* hashtable ******************************************************************/
100
101 struct hashtable {            
102 #if defined(ENABLE_THREADS)
103         java_object_t      *header;         /* required for locking               */
104 #endif
105         u4                  size;           /* current size of the hashtable      */
106         u4                  entries;        /* number of entries in the table     */
107         void              **ptr;            /* pointer to hashtable               */
108 };
109
110
111 /* function prototypes ********************************************************/
112
113 /* create hashtable */
114 void hashtable_create(hashtable *hash, u4 size);
115
116 /* creates and resizes a hashtable */
117 hashtable *hashtable_resize(hashtable *hash, u4 size);
118
119 /* frees a hashtable */
120 void hashtable_free(hashtable *hash);
121
122 #endif /* _HASHTABLE_H */
123
124
125 /*
126  * These are local overrides for various environment variables in Emacs.
127  * Please do not remove this and leave it at the end of the file, where
128  * Emacs will automagically detect them.
129  * ---------------------------------------------------------------------
130  * Local variables:
131  * mode: c
132  * indent-tabs-mode: t
133  * c-basic-offset: 4
134  * tab-width: 4
135  * End:
136  */