1 /* src/toolbox/hashtable.h - functions for internal hashtables
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
8 This file is part of CACAO.
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.
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.
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
25 Contact: cacao@cacaojvm.org
27 Authors: Reinhard Grafl
36 /* forward typedefs ***********************************************************/
38 typedef struct hashtable hashtable;
44 #include "vm/global.h"
45 #include "vmcore/utf8.h"
48 /* data structures for hashtables ********************************************
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.
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
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.
76 Example for the layout of a hashtable:
78 hashtable.ptr-->+-------------------+
82 +-------------------+ +-------------------+ +-------------------+
83 | hashtable element |-->| hashtable element |-->| hashtable element |-->NULL
84 +-------------------+ +-------------------+ +-------------------+
86 +-------------------+ +-------------------+
87 | hashtable element |-->| hashtable element |-->NULL
88 +-------------------+ +-------------------+
89 | hashtable element |-->NULL
99 /* hashtable ******************************************************************/
102 #if defined(ENABLE_THREADS)
103 java_object_t *header; /* required for locking */
105 u4 size; /* current size of the hashtable */
106 u4 entries; /* number of entries in the table */
107 void **ptr; /* pointer to hashtable */
111 /* function prototypes ********************************************************/
113 /* create hashtable */
114 void hashtable_create(hashtable *hash, u4 size);
116 /* creates and resizes a hashtable */
117 hashtable *hashtable_resize(hashtable *hash, u4 size);
119 /* frees a hashtable */
120 void hashtable_free(hashtable *hash);
122 #endif /* _HASHTABLE_H */
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 * ---------------------------------------------------------------------
132 * indent-tabs-mode: t