1 /* src/vm/hashtable.h - functions for internal hashtables
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Reinhard Grafl
29 Changes: Christian Thalinger
31 $Id: hashtable.h 3836 2005-12-01 23:45:13Z twisti $
39 /* forward typedefs ***********************************************************/
41 typedef struct hashtable hashtable;
49 /* data structures for hashtables ********************************************
51 All utf-symbols, javastrings and classes are stored in global
52 hashtables, so every symbol exists only once. Equal symbols have
53 identical pointers. The functions for adding hashtable elements
54 search the table for the element with the specified name/text and
55 return it on success. Otherwise a new hashtable element is created.
57 The hashtables use external linking for handling collisions. The
58 hashtable structure contains a pointer <ptr> to the array of
59 hashtable slots. The number of hashtable slots and therefore the
60 size of this array is specified by the element <size> of hashtable
61 structure. <entries> contains the number of all hashtable elements
62 stored in the table, including those in the external chains. The
63 hashtable element structures (utf, literalstring, classinfo)
64 contain both a pointer to the next hashtable element as a link for
65 the external hash chain and the key of the element. The key is
66 computed from the text of the string or the classname by using up
69 If the number of entries in the hashtable exceeds twice the size of
70 the hashtableslot-array it is supposed that the average length of
71 the external chains has reached a value beyond 2. Therefore the
72 functions for adding hashtable elements (utf_new, class_new,
73 literalstring_new) double the hashtableslot-array. In this
74 restructuring process all elements have to be inserted into the new
75 hashtable and new external chains must be built.
77 Example for the layout of a hashtable:
79 hashtable.ptr-->+-------------------+
83 +-------------------+ +-------------------+ +-------------------+
84 | hashtable element |-->| hashtable element |-->| hashtable element |-->NULL
85 +-------------------+ +-------------------+ +-------------------+
87 +-------------------+ +-------------------+
88 | hashtable element |-->| hashtable element |-->NULL
89 +-------------------+ +-------------------+
90 | hashtable element |-->NULL
100 /* hashtable ******************************************************************/
104 u4 entries; /* number of entries in the table */
105 void **ptr; /* pointer to hashtable */
109 /* function prototypes ********************************************************/
111 /* create hashtable */
112 void hashtable_create(hashtable *hash, u4 size);
114 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
115 void tables_lock(void);
116 void tables_unlock(void);
119 #endif /* _HASHTABLE_H */
123 * These are local overrides for various environment variables in Emacs.
124 * Please do not remove this and leave it at the end of the file, where
125 * Emacs will automagically detect them.
126 * ---------------------------------------------------------------------
129 * indent-tabs-mode: t