]> git.saurik.com Git - wxWidgets.git/blob - include/wx/hash.h
wxCHECK/wxCHECK_RET changes
[wxWidgets.git] / include / wx / hash.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: hash.h
3 // Purpose: wxHashTable class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef __WXHASHH__
13 #define __WXHASHH__
14
15 #ifdef __GNUG__
16 #pragma interface "hash.h"
17 #endif
18
19 #include "wx/object.h"
20 #include "wx/list.h"
21
22 /*
23 * A hash table is an array of user-definable size with lists
24 * of data items hanging off the array positions. Usually there'll
25 * be a hit, so no search is required; otherwise we'll have to run down
26 * the list to find the desired item.
27 */
28
29 class WXDLLEXPORT wxHashTable: public wxObject
30 {
31 DECLARE_DYNAMIC_CLASS(wxHashTable)
32
33 public:
34 int n;
35 int current_position;
36 wxNode *current_node;
37
38 unsigned int key_type;
39 wxList **hash_table;
40
41 wxHashTable(const int the_key_type = wxKEY_INTEGER, const int size = 1000);
42 ~wxHashTable(void);
43
44 bool Create(const int the_key_type = wxKEY_INTEGER, const int size = 1000);
45
46 // Note that there are 2 forms of Put, Get.
47 // With a key and a value, the *value* will be checked
48 // when a collision is detected. Otherwise, if there are
49 // 2 items with a different value but the same key,
50 // we'll retrieve the WRONG ONE. So where possible,
51 // supply the required value along with the key.
52 // In fact, the value-only versions make a key, and still store
53 // the value. The use of an explicit key might be required
54 // e.g. when combining several values into one key.
55 // When doing that, it's highly likely we'll get a collision,
56 // e.g. 1 + 2 = 3, 2 + 1 = 3.
57
58 // key and value are NOT necessarily the same
59 void Put(const long key, const long value, wxObject *object);
60 void Put(const long key, const char *value, wxObject *object);
61
62 // key and value are the same
63 void Put(const long value, wxObject *object);
64 void Put(const char *value, wxObject *object);
65
66 // key and value not the same
67 wxObject *Get(const long key, const long value) const;
68 wxObject *Get(const long key, const char *value) const;
69
70 // key and value are the same
71 wxObject *Get(const long value) const;
72 wxObject *Get(const char *value) const;
73
74 // Deletes entry and returns data if found
75 wxObject *Delete(const long key);
76 wxObject *Delete(const char *key);
77
78 wxObject *Delete(const long key, const int value);
79 wxObject *Delete(const long key, const char *value);
80
81 // Construct your own integer key from a string, e.g. in case
82 // you need to combine it with something
83 long MakeKey(const char *string) const;
84
85 // Way of iterating through whole hash table (e.g. to delete everything)
86 // Not necessary, of course, if you're only storing pointers to
87 // objects maintained separately
88
89 void BeginFind(void);
90 wxNode *Next(void);
91
92 void DeleteContents(const bool flag);
93 void Clear(void);
94
95 };
96
97 #endif
98 // __WXHASHH__