]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
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 | ||
34138703 JS |
12 | #ifndef _WX_WXHASHH__ |
13 | #define _WX_WXHASHH__ | |
c801d85f KB |
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 | ||
debe6624 | 41 | wxHashTable(int the_key_type = wxKEY_INTEGER, int size = 1000); |
c801d85f | 42 | ~wxHashTable(void); |
e55ad60e | 43 | |
4e67bfc7 VS |
44 | // copy ctor and assignment operator |
45 | wxHashTable(const wxHashTable& table) { DoCopy(table); } | |
46 | wxHashTable& operator=(const wxHashTable& table) { Clear(); DoCopy(table); return *this; } | |
47 | void DoCopy(const wxHashTable& table); | |
48 | ||
e55ad60e | 49 | void Destroy(void); // Robert Roebling |
c801d85f | 50 | |
debe6624 | 51 | bool Create(int the_key_type = wxKEY_INTEGER, int size = 1000); |
c801d85f KB |
52 | |
53 | // Note that there are 2 forms of Put, Get. | |
54 | // With a key and a value, the *value* will be checked | |
55 | // when a collision is detected. Otherwise, if there are | |
56 | // 2 items with a different value but the same key, | |
57 | // we'll retrieve the WRONG ONE. So where possible, | |
58 | // supply the required value along with the key. | |
59 | // In fact, the value-only versions make a key, and still store | |
60 | // the value. The use of an explicit key might be required | |
61 | // e.g. when combining several values into one key. | |
62 | // When doing that, it's highly likely we'll get a collision, | |
63 | // e.g. 1 + 2 = 3, 2 + 1 = 3. | |
64 | ||
65 | // key and value are NOT necessarily the same | |
debe6624 | 66 | void Put(long key, long value, wxObject *object); |
9d2f3c71 | 67 | void Put(long key, const wxChar *value, wxObject *object); |
c801d85f KB |
68 | |
69 | // key and value are the same | |
debe6624 | 70 | void Put(long value, wxObject *object); |
9d2f3c71 | 71 | void Put(const wxChar *value, wxObject *object); |
c801d85f KB |
72 | |
73 | // key and value not the same | |
debe6624 | 74 | wxObject *Get(long key, long value) const; |
9d2f3c71 | 75 | wxObject *Get(long key, const wxChar *value) const; |
c801d85f KB |
76 | |
77 | // key and value are the same | |
debe6624 | 78 | wxObject *Get(long value) const; |
9d2f3c71 | 79 | wxObject *Get(const wxChar *value) const; |
c801d85f KB |
80 | |
81 | // Deletes entry and returns data if found | |
debe6624 | 82 | wxObject *Delete(long key); |
9d2f3c71 | 83 | wxObject *Delete(const wxChar *key); |
c801d85f | 84 | |
debe6624 | 85 | wxObject *Delete(long key, int value); |
9d2f3c71 | 86 | wxObject *Delete(long key, const wxChar *value); |
c801d85f KB |
87 | |
88 | // Construct your own integer key from a string, e.g. in case | |
89 | // you need to combine it with something | |
9d2f3c71 | 90 | long MakeKey(const wxChar *string) const; |
c801d85f KB |
91 | |
92 | // Way of iterating through whole hash table (e.g. to delete everything) | |
93 | // Not necessary, of course, if you're only storing pointers to | |
94 | // objects maintained separately | |
95 | ||
96 | void BeginFind(void); | |
97 | wxNode *Next(void); | |
98 | ||
debe6624 | 99 | void DeleteContents(bool flag); |
c801d85f KB |
100 | void Clear(void); |
101 | ||
102 | }; | |
103 | ||
104 | #endif | |
34138703 | 105 | // _WX_WXHASHH__ |