1 /*
2 * Copyright (c) 1997, 2003, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef _DICT_
26 #define _DICT_
27 // Dictionaries - An Abstract Data Type
28 //INTERFACE
29 class ostream;
30 class Dict;
31
32 // These dictionaries define a key-value mapping. They can be inserted to,
33 // searched or deleted from. They grow and shrink as needed. The key is a
34 // pointer to something (or anything which can be stored in a pointer). A
35 // key comparison routine determines if two keys are equal or not. A hash
36 // function can be provided; if it's not provided the key itself is used
37 // instead. A nice string hash function is included.
38 typedef int32 (*CmpKey)(const void *key1, const void *key2);
39 typedef int (*Hash)(const void *key);
40 typedef void (*FuncDict)(const void *key, const void *val, Dict *d);
41
42 class Dict : public ResourceObj { // Dictionary structure
43 private:
44 class Arena *_arena; // Where to draw storage from
98 int32 cmpkey(const void *key1, const void *key2);
99
100 //------------------------------Iteration--------------------------------------
101 // The class of dictionary iterators. Fails in the presences of modifications
102 // to the dictionary during iteration (including searches).
103 // Usage: for( DictI i(dict); i.test(); ++i ) { body = i.key; body = i.value;}
104 class DictI {
105 private:
106 const Dict *_d; // Dictionary being iterated over
107 uint _i; // Counter over the bins
108 uint _j; // Counter inside each bin
109 public:
110 const void *_key, *_value; // Easy access to the key-value pair
111 DictI( const Dict *d ) {reset(d);}; // Create a new iterator
112 void reset( const Dict *dict ); // Reset existing iterator
113 void operator ++(void); // Increment iterator
114 int test(void) { return _i<_d->_size;} // Test for end of iteration
115 };
116
117 #endif // _DICT_
|
1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_VM_LIBADT_DICT_HPP
26 #define SHARE_VM_LIBADT_DICT_HPP
27
28 #include "libadt/port.hpp"
29
30 #ifndef _DICT_
31 #define _DICT_
32 // Dictionaries - An Abstract Data Type
33 //INTERFACE
34 class ostream;
35 class Dict;
36
37 // These dictionaries define a key-value mapping. They can be inserted to,
38 // searched or deleted from. They grow and shrink as needed. The key is a
39 // pointer to something (or anything which can be stored in a pointer). A
40 // key comparison routine determines if two keys are equal or not. A hash
41 // function can be provided; if it's not provided the key itself is used
42 // instead. A nice string hash function is included.
43 typedef int32 (*CmpKey)(const void *key1, const void *key2);
44 typedef int (*Hash)(const void *key);
45 typedef void (*FuncDict)(const void *key, const void *val, Dict *d);
46
47 class Dict : public ResourceObj { // Dictionary structure
48 private:
49 class Arena *_arena; // Where to draw storage from
103 int32 cmpkey(const void *key1, const void *key2);
104
105 //------------------------------Iteration--------------------------------------
106 // The class of dictionary iterators. Fails in the presences of modifications
107 // to the dictionary during iteration (including searches).
108 // Usage: for( DictI i(dict); i.test(); ++i ) { body = i.key; body = i.value;}
109 class DictI {
110 private:
111 const Dict *_d; // Dictionary being iterated over
112 uint _i; // Counter over the bins
113 uint _j; // Counter inside each bin
114 public:
115 const void *_key, *_value; // Easy access to the key-value pair
116 DictI( const Dict *d ) {reset(d);}; // Create a new iterator
117 void reset( const Dict *dict ); // Reset existing iterator
118 void operator ++(void); // Increment iterator
119 int test(void) { return _i<_d->_size;} // Test for end of iteration
120 };
121
122 #endif // _DICT_
123
124 #endif // SHARE_VM_LIBADT_DICT_HPP
|