]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/hash.h
Applied #15226 with modifications: wxRichTextCtrl: Implement setting properties with...
[wxWidgets.git] / interface / wx / hash.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: hash.h
e54c96f1 3// Purpose: interface of wxHashTable
23324ae1 4// Author: wxWidgets team
526954c5 5// Licence: wxWindows licence
23324ae1
FM
6/////////////////////////////////////////////////////////////////////////////
7
8/**
9 @class wxHashTable
7c913512 10
9cc56d1f
FM
11 @deprecated
12 Please note that this class is retained for backward compatibility
23324ae1 13 reasons; you should use wxHashMap.
7c913512 14
23324ae1 15 This class provides hash table functionality for wxWidgets, and for an
9cc56d1f
FM
16 application if it wishes. Data can be hashed on an integer or string key.
17
18 Example:
19 @code
20 wxHashTable table(wxKEY_STRING);
21
22 wxPoint *point = new wxPoint(100, 200);
23 table.Put("point 1", point);
24
25 ....
26
27 wxPoint *found_point = (wxPoint *)table.Get("point 1");
28 @endcode
29
30 A hash table is implemented as an array of pointers to lists.
31 When no data has been stored, the hash table takes only a little more space
32 than this array (default size is 1000). When a data item is added, an integer
33 is constructed from the integer or string key that is within the bounds of the array.
34 If the array element is @NULL, a new (keyed) list is created for the element.
35 Then the data object is appended to the list, storing the key in case other
36 data objects need to be stored in the list also (when a 'collision' occurs).
37
38 Retrieval involves recalculating the array index from the key, and searching
39 along the keyed list for the data object whose stored key matches the passed key.
40 Obviously this is quicker when there are fewer collisions, so hashing will
41 become inefficient if the number of items to be stored greatly exceeds the
42 size of the hash table.
7c913512 43
23324ae1
FM
44 @library{wxbase}
45 @category{containers}
7c913512 46
e54c96f1 47 @see wxList
23324ae1
FM
48*/
49class wxHashTable : public wxObject
50{
51public:
52 /**
4cc4bfaf
FM
53 Constructor. @a key_type is one of wxKEY_INTEGER, or wxKEY_STRING,
54 and indicates what sort of keying is required. @a size is optional.
23324ae1 55 */
a44f3b5a 56 wxHashTable(wxKeyType key_type = wxKEY_INTEGER, size_t size = 1000);
23324ae1
FM
57
58 /**
59 Destroys the hash table.
60 */
adaaa686 61 virtual ~wxHashTable();
23324ae1
FM
62
63 /**
9cc56d1f
FM
64 The counterpart of Next(). If the application wishes to iterate
65 through all the data in the hash table, it can call BeginFind() and
66 then loop on Next().
23324ae1
FM
67 */
68 void BeginFind();
69
70 /**
71 Clears the hash table of all nodes (but as usual, doesn't delete user data).
72 */
73 void Clear();
74
75 //@{
76 /**
77 Deletes entry in hash table and returns the user's data (if found).
78 */
4cc4bfaf
FM
79 wxObject* Delete(long key);
80 wxObject* Delete(const wxString& key);
23324ae1
FM
81 //@}
82
83 /**
9cc56d1f
FM
84 If set to @true data stored in hash table will be deleted when hash table
85 object is destroyed.
23324ae1
FM
86 */
87 void DeleteContents(bool flag);
88
89 //@{
90 /**
9cc56d1f
FM
91 Gets data from the hash table, using an integer or string key
92 (depending on which has table constructor was used).
23324ae1 93 */
4cc4bfaf
FM
94 wxObject* Get(long key);
95 wxObject* Get(const char* key);
23324ae1
FM
96 //@}
97
98 /**
99 Returns the number of elements in the hash table.
100 */
328f5751 101 size_t GetCount() const;
23324ae1
FM
102
103 /**
104 Makes an integer key out of a string. An application may wish to make a key
105 explicitly (for instance when combining two data values to form a key).
106 */
adaaa686 107 static long MakeKey(const wxString& string);
23324ae1
FM
108
109 /**
110 If the application wishes to iterate through all the data in the hash
9cc56d1f
FM
111 table, it can call BeginFind() and then loop on Next(). This function
112 returns a @b wxHashTable::Node pointer (or @NULL if there are no more nodes).
113
23324ae1
FM
114 The return value is functionally equivalent to @b wxNode but might not be
115 implemented as a @b wxNode. The user will probably only wish to use the
9cc56d1f 116 wxNode::GetData() method to retrieve the data; the node may also be deleted.
23324ae1 117 */
4cc4bfaf 118 wxHashTable::Node* Next();
23324ae1
FM
119
120 //@{
121 /**
122 Inserts data into the hash table, using an integer or string key (depending on
9cc56d1f
FM
123 which has table constructor was used).
124 The key string is copied and stored by the hash table implementation.
23324ae1 125 */
4cc4bfaf
FM
126 void Put(long key, wxObject* object);
127 void Put(const char* key, wxObject* object);
23324ae1
FM
128 //@}
129};
e54c96f1 130