home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_07_08 / v7n8092a.txt < prev    next >
Text File  |  1988-12-21  |  923b  |  30 lines

  1. /* include file for hash searching */
  2.  
  3.  
  4. class hashtable
  5. { // private:
  6.   typedef struct entry { char *key, *data; } ENTRY;
  7.   unsigned prime(unsigned size); // generate prime number
  8.   int hash(char *str);         // hash function
  9.   int hcreate(unsigned nel);     // create hash table
  10.   static ENTRY *hash_table;      // pointer to hash table
  11.   static unsigned num_elem;     // max num table elements
  12.   static unsigned count;     // current table entry count
  13.  
  14.   public:
  15.     typedef enum { fIND, ENTER, DELETE } ACTION;
  16.     hashtable(unsigned size)    // constructor
  17.     { 
  18.       hcreate(size); 
  19.     }
  20.     void hdestroy();                
  21.     // search for an item
  22.     ENTRY *hsearch(ENTRY item, ACTION action);  
  23.     unsigned hcount();        // num items in table
  24.     unsigned hsize();        // hash table size
  25.     int hwrite();        // write hash table
  26.     int hread();        // read hash table
  27.     ~hashtable() { hdestroy(); } // destructor
  28. };
  29.  
  30.