Back to index

plt-scheme  4.2.1
wx_hash.h
Go to the documentation of this file.
00001 /*                                                      -*- C++ -*-
00002  * File:             wx_hash.h
00003  * Purpose:   Basic hash table implementation
00004  * Author:           Julian Smart
00005  * Created:   1993
00006  * Updated:   
00007  * Copyright: (c) 2004-2009 PLT Scheme Inc.
00008  * Copyright: (c) 1993, AIAI, University of Edinburgh
00009  */
00010 
00011 #ifndef wxb_hashh
00012 #define wxb_hashh
00013 
00014 #ifdef __GNUG__
00015 # ifndef wx_mac
00016 #  pragma interface
00017 # endif
00018 #endif
00019 
00020 #ifndef wx_xt
00021 #   include "wx_obj.h"
00022 #   include "wx_list.h"
00023 #endif
00024 
00025 /*
00026  * A hash table is an array of user-definable size with lists
00027  * of data items hanging off the array positions.  Usually there'll
00028  * be a hit, so no search is required; otherwise we'll have to run down
00029  * the list to find the desired item.
00030 */
00031 
00032 #ifdef IN_CPROTO
00033 typedef       void    *wxHashTable ;
00034 #else
00035 
00036 class wxHashTable: public wxObject
00037 {
00038 
00039  public:
00040   int n;
00041   int current_position;
00042   wxNode *current_node;
00043 
00044   wxList **hash_table;
00045 
00046   wxHashTable(int the_key_type = 0, int size = 1000);
00047   ~wxHashTable(void);
00048 
00049   // key and value are the same
00050   void Put(long value, wxObject *object);
00051   void Put(const char *value, wxObject *object);
00052 
00053   // key and value are the same
00054   wxObject *Get(long value);
00055   wxObject *Get(const char *value);
00056 
00057   // Deletes entry and returns data if found
00058   wxObject *Delete(long key);
00059   wxObject *Delete(const char *key);
00060 
00061   // Construct your own integer key from a string, e.g. in case
00062   // you need to combine it with something
00063   int MakeKey(const char *string);
00064   int MakeKey(long val);
00065 
00066   // Way of iterating through whole hash table (e.g. to delete everything)
00067   // Not necessary, of course, if you're only storing pointers to
00068   // objects maintained separately
00069 
00070   void BeginFind(void);
00071   wxNode *Next(void);
00072 
00073   void DeleteContents(Bool flag);
00074   void Clear(void);
00075 
00076 private:
00077   wxList *GetList(int position, KeyType ktype = wxKEY_INTEGER, Bool makeit = TRUE);
00078 };
00079 
00080 /* Special hash table implementation for widgets. */
00081 class wxNonlockingHashTable
00082 {
00083   struct Bucket *buckets;
00084   long numbuckets, numwidgets, numused;
00085  public:
00086   wxNonlockingHashTable(void);
00087   ~wxNonlockingHashTable();
00088   void Put(long widget, wxObject *object);
00089   wxObject *Get(long widget);
00090   void Delete(long widget);
00091   void DeleteObject(wxObject *object);
00092   inline void Append(long w, wxObject *o) { Put(w, o); }
00093   inline wxObject *Find(long w) { return Get(w); }
00094 };
00095 
00096 #endif // IN_CPROTO
00097 #endif // wxb_hashh