Annotation of researchv10no/cmd/cfront/ooptcfront/hash.H, revision 1.1.1.1

1.1       root        1: /* -*- Mode:C++ -*-
                      2:     $Header: /usr2/odi/objectstore.src/libos/RCS/hash.H,v 1.4 89/09/26 09:37:31 benson Exp $
                      3: 
                      4:     Copyright (c) 1989 by Object Design, Inc., Burlington, Mass.
                      5:     All rights reserved.
                      6: 
                      7: */
                      8: 
                      9: #ifndef _Hash_h
                     10: #define _Hash_h 1
                     11: 
                     12: typedef void (*Error_Proc) (const char*) ;
                     13: 
                     14: extern void default_Hash_error_handler (const char*) ;
                     15: extern Error_Proc Hash_error_handler ;
                     16: extern Error_Proc set_Hash_error_handler (Error_Proc f) ;
                     17: 
                     18: #ifndef _hash_typedefs
                     19: #define _hash_typedefs 1
                     20: typedef void (*intProc)(int) ;
                     21: #endif
                     22: 
                     23: #define DEFAULT_INITIAL_HASH_SIZE 100
                     24: 
                     25: struct HashTableEntry
                     26: {
                     27:   int                   key ;
                     28:   int                   cont ;
                     29:   char                  status ;
                     30: } ;
                     31: 
                     32: class HashWalker ;
                     33: 
                     34: class Hash
                     35: {
                     36:   friend class          HashWalker ;
                     37: 
                     38:   HashTableEntry*       tab ;
                     39:   int                   size ;
                     40:   int                   entry_count ;
                     41: 
                     42: public:
                     43:   unsigned int         (*key_hash_function)(int)  ;
                     44:    int                 (*key_key_equality_function) (int, int) ;
                     45: 
                     46:   unsigned int          key_hash(int  a) ;
                     47:   int                   key_key_eq(int a, int  b);    
                     48: 
                     49:                         Hash(int sz) ;
                     50:                         Hash(Hash& a) ;
                     51:                         ~Hash() ;
                     52: 
                     53:   Hash&                 operator= (Hash& a) ;
                     54: 
                     55:   int                   count() ;
                     56:   int                   empty() ;
                     57:   int                   full() ;
                     58:   int                   capacity() ;
                     59: 
                     60:   void                  clear() ;
                     61:   void                  resize(int newsize) ;
                     62: 
                     63:   enum insert_action   { probe, insert, replace };
                     64:   void                 action (int key, int val, insert_action what,
                     65:                                int& found, int& old_val);
                     66:   int&                  operator [] (int  k) ;
                     67:   int                   contains(int  key) ;
                     68:   int                   del(int  key) ;
                     69: 
                     70:   void                  apply (intProc f) ;
                     71:   void                  error(const char* msg) ;
                     72: } ;
                     73: 
                     74: class HashWalker
                     75: {
                     76:   Hash*     h ;
                     77:   int                   pos ;
                     78: 
                     79: public:
                     80:                         HashWalker(Hash& l) ;
                     81:                         ~HashWalker() ;
                     82: 
                     83:   int                   null() ;
                     84:   int                   valid() ;
                     85:                         operator void* () ;
                     86:   int                   operator ! () ;
                     87:   void                  advance() ;
                     88:   void                  reset() ;
                     89:   void                  reset(Hash& l) ;
                     90:   const int&            key() ;
                     91:   int&                  get() ;
                     92: } ;
                     93: 
                     94: inline unsigned int Hash::key_hash(int a)
                     95: {
                     96: #ifdef HASHFUNCTION
                     97:   return HASHFUNCTION(a) ;
                     98: #else
                     99:   return (*key_hash_function)(a) ;
                    100: #endif
                    101: }
                    102: 
                    103: inline int Hash::key_key_eq(int a, int b)
                    104: {
                    105: #ifdef EQUALITYFUNCTION
                    106:   return EQUALITYFUNCTION(a, b) ;
                    107: #else
                    108:   return (*key_key_equality_function)(a, b) ;
                    109: #endif
                    110: }
                    111: 
                    112: 
                    113: inline Hash::~Hash()
                    114: {
                    115:   delete [size] tab ;
                    116: }
                    117: 
                    118: inline int Hash::count()
                    119: {
                    120:   return entry_count ;
                    121: }
                    122: 
                    123: inline int Hash::empty()
                    124: {
                    125:   return entry_count == 0 ;
                    126: }
                    127: 
                    128: inline int Hash::full()
                    129: {
                    130:   return entry_count == size ;
                    131: }
                    132: 
                    133: inline int Hash::capacity()
                    134: {
                    135:   return size ;
                    136: }
                    137: inline HashWalker::HashWalker(Hash& a)
                    138: {
                    139:   h = &a ;
                    140:   reset() ;
                    141: }
                    142: 
                    143: inline void HashWalker::reset(Hash& a)
                    144: {
                    145:   h = &a ;
                    146:   reset() ;
                    147: }
                    148: 
                    149: 
                    150: inline HashWalker::~HashWalker() {}
                    151: 
                    152: inline int HashWalker::null()
                    153: {
                    154:   return pos < 0 ;
                    155: }
                    156: 
                    157: inline int HashWalker::valid()
                    158: {
                    159:   return pos >= 0 ;
                    160: }
                    161: 
                    162: inline HashWalker::operator void* ()
                    163: {
                    164:   return (pos < 0)? 0 : this ;
                    165: }
                    166: 
                    167: inline int HashWalker::operator ! ()
                    168: {
                    169:   return (pos < 0) ;
                    170: }
                    171: 
                    172: 
                    173: inline const int& HashWalker::key()
                    174: {
                    175:   if (pos < 0)
                    176:     h->error("operation on null Walker") ;
                    177:   return h->tab[pos].key ;
                    178: }
                    179: 
                    180: inline int& HashWalker::get()
                    181: {
                    182:   if (pos < 0)
                    183:     h->error("operation on null Walker") ;
                    184:   return h->tab[pos].cont ;
                    185: }
                    186: 
                    187: #endif
                    188: 
                    189: 
                    190: 
                    191: 
                    192: /*
                    193:    $Log:       hash.H,v $
                    194: Revision 1.4  89/09/26  09:37:31  benson
                    195: Don't refer to hash functions using syntax that suggests staticity.
                    196: 
                    197: Revision 1.3  89/09/26  09:34:22  benson
                    198: hash functions aren't static anymore. They never had any business
                    199: being static, and nothing should depend on it.
                    200: 
                    201: 
                    202: Revision 1.2  89/07/11  09:03:46  benson
                    203: add a procedure to Hash to circument the idiotic [] interface.
                    204: 
                    205: Revision 1.1  89/05/22  13:31:29  cwl
                    206: Initial revision
                    207: 
                    208:  * Revision 1.1  89/05/17  16:06:08  cwl
                    209:  * Initial revision
                    210:  * 
                    211:  * Revision 1.2  89/05/15  14:55:43  cwl
                    212:  * remove static rcs decls
                    213:  * 
                    214:  * Revision 1.1  89/05/12  14:26:52  cwl
                    215:  * Initial revision
                    216:  * 
                    217: 
                    218:    end_log
                    219: */
                    220: 
                    221: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.