home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / code / wxwin140 / include / wx_hash.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  3.5 KB  |  107 lines

  1. /*
  2.  * File:     wx_hash.h
  3.  * Purpose:  Basic hash table implementation
  4.  *
  5.  *                       wxWindows 1.40
  6.  * Copyright (c) 1993 Artificial Intelligence Applications Institute,
  7.  *                   The University of Edinburgh
  8.  *
  9.  *                     Author: Julian Smart
  10.  *                       Date: 18-4-93
  11.  *
  12.  * Permission to use, copy, modify, and distribute this software and its
  13.  * documentation for any purpose is hereby granted without fee, provided
  14.  * that the above copyright notice, author statement and this permission
  15.  * notice appear in all copies of this software and related documentation.
  16.  *
  17.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS,
  18.  * IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF
  19.  * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
  20.  *
  21.  * IN NO EVENT SHALL THE ARTIFICIAL INTELLIGENCE APPLICATIONS INSTITUTE OR THE
  22.  * UNIVERSITY OF EDINBURGH BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR
  23.  * CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM
  24.  * LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF THE POSSIBILITY OF
  25.  * DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH
  26.  * THE USE OR PERFORMANCE OF THIS SOFTWARE.
  27.  */
  28.  
  29. #ifndef wx_hashh
  30. #define wx_hashh
  31.  
  32. #include "wx_obj.h"
  33. #include "wx_list.h"
  34.  
  35. /*
  36.  * A hash table is an array of user-definable size with lists
  37.  * of data items hanging off the array positions.  Usually there'll
  38.  * be a hit, so no search is required; otherwise we'll have to run down
  39.  * the list to find the desired item.
  40. */
  41.  
  42. class wxHashTable: public wxObject
  43. {
  44.  public:
  45.   int n;
  46.   int current_position;
  47.   wxNode *current_node;
  48.  
  49.   unsigned int key_type;
  50.   wxList **hash_table;
  51.  
  52.   wxHashTable(unsigned int the_key_type, int size = 1000);
  53.   ~wxHashTable(void);
  54.  
  55.   // Note that there are 2 forms of Put, Get.
  56.   // With a key and a value, the *value* will be checked
  57.   // when a collision is detected. Otherwise, if there are
  58.   // 2 items with a different value but the same key,
  59.   // we'll retrieve the WRONG ONE. So where possible,
  60.   // supply the required value along with the key.
  61.   // In fact, the value-only versions make a key, and still store
  62.   // the value. The use of an explicit key might be required
  63.   // e.g. when combining several values into one key.
  64.   // When doing that, it's highly likely we'll get a collision,
  65.   // e.g. 1 + 2 = 3, 2 + 1 = 3.
  66.  
  67.   // key and value are NOT necessarily the same
  68.   void Put(long key, long value, wxObject *object);
  69.   void Put(long key, char *value, wxObject *object);
  70.  
  71.   // key and value are the same
  72.   void Put(long value, wxObject *object);
  73.   void Put(char *value, wxObject *object);
  74.  
  75.   // key and value not the same
  76.   wxObject *Get(long key, long value);
  77.   wxObject *Get(long key, char *value);
  78.  
  79.   // key and value are the same
  80.   wxObject *Get(long value);
  81.   wxObject *Get(char *value);
  82.  
  83.   // Deletes entry and returns data if found
  84.   wxObject *Delete(long key);
  85.   wxObject *Delete(char *key);
  86.  
  87.   wxObject *Delete(long key, int value);
  88.   wxObject *Delete(long key, char *value);
  89.  
  90.   // Construct your own integer key from a string, e.g. in case
  91.   // you need to combine it with something
  92.   long MakeKey(char *string);
  93.  
  94.   // Way of iterating through whole hash table (e.g. to delete everything)
  95.   // Not necessary, of course, if you're only storing pointers to
  96.   // objects maintained separately
  97.  
  98.   void BeginFind(void);
  99.   wxNode *Next(void);
  100.  
  101.   void DeleteContents(Bool flag);
  102.   void Clear(void);
  103.  
  104. };
  105.  
  106. #endif // wx_hashh
  107.