src/share/vm/adlc/dict2.hpp

Print this page


   1 /*
   2  * Copyright (c) 1998, 2000, 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 
  29 
  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 int  (*CmpKey)(const void *key1, const void *key2);
  39 typedef int  (*Hash)(const void *key);
  40 typedef void (*PrintKeyOrValue)(const void *key_or_value);
  41 typedef void (*FuncDict)(const void *key, const void *val, Dict *d);
  42 
  43 class Dict { // Dictionary structure
  44  private:
  45   class Arena *_arena;          // Where to draw storage from
  46   class bucket *_bin;           // Hash table is array of buckets


 100 // Slimey cheap key comparator.
 101 int cmpkey(const void *key1, const void *key2);
 102 
 103 //------------------------------Iteration--------------------------------------
 104 // The class of dictionary iterators.  Fails in the presences of modifications
 105 // to the dictionary during iteration (including searches).
 106 // Usage:  for( DictI i(dict); i.test(); ++i ) { body = i.key; body = i.value;}
 107 class DictI {
 108  private:
 109   const Dict *_d;               // Dictionary being iterated over
 110   int _i;                      // Counter over the bins
 111   int _j;                      // Counter inside each bin
 112  public:
 113   const void *_key, *_value;          // Easy access to the key-value pair
 114   DictI( const Dict *d ) {reset(d);}; // Create a new iterator
 115   void reset( const Dict *dict );     // Reset existing iterator
 116   void operator ++(void);             // Increment iterator
 117   int test(void) { return _i<_d->_size;} // Test for end of iteration
 118 };
 119 
 120 #endif // _DICT_
   1 /*
   2  * Copyright (c) 1998, 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_ADLC_DICT2_HPP
  26 #define SHARE_VM_ADLC_DICT2_HPP
  27 
  28 // Dictionaries - An Abstract Data Type
  29 
  30 
  31 class Dict;
  32 
  33 // These dictionaries define a key-value mapping.  They can be inserted to,
  34 // searched or deleted from.  They grow and shrink as needed.  The key is a
  35 // pointer to something (or anything which can be stored in a pointer).  A
  36 // key comparison routine determines if two keys are equal or not.  A hash
  37 // function can be provided; if it's not provided the key itself is used
  38 // instead.  A nice string hash function is included.
  39 typedef int  (*CmpKey)(const void *key1, const void *key2);
  40 typedef int  (*Hash)(const void *key);
  41 typedef void (*PrintKeyOrValue)(const void *key_or_value);
  42 typedef void (*FuncDict)(const void *key, const void *val, Dict *d);
  43 
  44 class Dict { // Dictionary structure
  45  private:
  46   class Arena *_arena;          // Where to draw storage from
  47   class bucket *_bin;           // Hash table is array of buckets


 101 // Slimey cheap key comparator.
 102 int cmpkey(const void *key1, const void *key2);
 103 
 104 //------------------------------Iteration--------------------------------------
 105 // The class of dictionary iterators.  Fails in the presences of modifications
 106 // to the dictionary during iteration (including searches).
 107 // Usage:  for( DictI i(dict); i.test(); ++i ) { body = i.key; body = i.value;}
 108 class DictI {
 109  private:
 110   const Dict *_d;               // Dictionary being iterated over
 111   int _i;                      // Counter over the bins
 112   int _j;                      // Counter inside each bin
 113  public:
 114   const void *_key, *_value;          // Easy access to the key-value pair
 115   DictI( const Dict *d ) {reset(d);}; // Create a new iterator
 116   void reset( const Dict *dict );     // Reset existing iterator
 117   void operator ++(void);             // Increment iterator
 118   int test(void) { return _i<_d->_size;} // Test for end of iteration
 119 };
 120 
 121 #endif // SHARE_VM_ADLC_DICT2_HPP