]>
Commit | Line | Data |
---|---|---|
a660d684 KB |
1 | \section{\class{wxHashTable}}\label{wxhashtable} |
2 | ||
e676441f MB |
3 | {\bf Please note} that this class is retained for backward compatibility |
4 | reasons; you should use \helpref{wxHashMap}{wxhashmap}. | |
5 | ||
fc2171bd | 6 | This class provides hash table functionality for wxWidgets, and for an |
a660d684 KB |
7 | application if it wishes. Data can be hashed on an integer or string |
8 | key. | |
9 | ||
10 | \wxheading{Derived from} | |
11 | ||
12 | \helpref{wxObject}{wxobject} | |
13 | ||
954b8ae6 JS |
14 | \wxheading{Include files} |
15 | ||
16 | <wx/hash.h> | |
17 | ||
a7af285d VZ |
18 | \wxheading{Library} |
19 | ||
20 | \helpref{wxBase}{librarieslist} | |
21 | ||
a660d684 KB |
22 | \wxheading{Example} |
23 | ||
24 | Below is an example of using a hash table. | |
25 | ||
26 | \begin{verbatim} | |
7445e247 | 27 | wxHashTable table(wxKEY_STRING); |
a660d684 KB |
28 | |
29 | wxPoint *point = new wxPoint(100, 200); | |
30 | table.Put("point 1", point); | |
31 | ||
32 | .... | |
33 | ||
34 | wxPoint *found_point = (wxPoint *)table.Get("point 1"); | |
35 | \end{verbatim} | |
36 | ||
37 | A hash table is implemented as an array of pointers to lists. When no | |
38 | data has been stored, the hash table takes only a little more space than | |
39 | this array (default size is 1000). When a data item is added, an | |
40 | integer is constructed from the integer or string key that is within the | |
41 | bounds of the array. If the array element is NULL, a new (keyed) list is | |
42 | created for the element. Then the data object is appended to the list, | |
43 | storing the key in case other data objects need to be stored in the list | |
44 | also (when a `collision' occurs). | |
45 | ||
46 | Retrieval involves recalculating the array index from the key, and searching | |
47 | along the keyed list for the data object whose stored key matches the passed | |
48 | key. Obviously this is quicker when there are fewer collisions, so hashing | |
49 | will become inefficient if the number of items to be stored greatly exceeds | |
50 | the size of the hash table. | |
51 | ||
52 | \wxheading{See also} | |
53 | ||
54 | \helpref{wxList}{wxlist} | |
55 | ||
56 | \latexignore{\rtfignore{\wxheading{Members}}} | |
57 | ||
f0e8a2d0 | 58 | \membersection{wxHashTable::wxHashTable}\label{wxhashtablector} |
a660d684 KB |
59 | |
60 | \func{}{wxHashTable}{\param{unsigned int}{ key\_type}, \param{int}{ size = 1000}} | |
61 | ||
62 | Constructor. {\it key\_type} is one of wxKEY\_INTEGER, or wxKEY\_STRING, | |
63 | and indicates what sort of keying is required. {\it size} is optional. | |
64 | ||
f0e8a2d0 | 65 | \membersection{wxHashTable::\destruct{wxHashTable}}\label{wxhashtabledtor} |
a660d684 KB |
66 | |
67 | \func{}{\destruct{wxHashTable}}{\void} | |
68 | ||
69 | Destroys the hash table. | |
70 | ||
f0e8a2d0 | 71 | \membersection{wxHashTable::BeginFind}\label{wxhashtablebeginfind} |
a660d684 KB |
72 | |
73 | \func{void}{BeginFind}{\void} | |
74 | ||
75 | The counterpart of {\it Next}. If the application wishes to iterate | |
76 | through all the data in the hash table, it can call {\it BeginFind} and | |
77 | then loop on {\it Next}. | |
78 | ||
f0e8a2d0 | 79 | \membersection{wxHashTable::Clear}\label{wxhashtableclear} |
a660d684 KB |
80 | |
81 | \func{void}{Clear}{\void} | |
82 | ||
83 | Clears the hash table of all nodes (but as usual, doesn't delete user data). | |
84 | ||
f0e8a2d0 | 85 | \membersection{wxHashTable::Delete}\label{wxhashtabledelete} |
a660d684 KB |
86 | |
87 | \func{wxObject *}{Delete}{\param{long}{ key}} | |
88 | ||
89 | \func{wxObject *}{Delete}{\param{const wxString\& }{ key}} | |
90 | ||
91 | Deletes entry in hash table and returns the user's data (if found). | |
92 | ||
f0e8a2d0 | 93 | \membersection{wxHashTable::DeleteContents}\label{wxhashtabledeletecontents} |
84b63045 VS |
94 | |
95 | \func{void}{DeleteContents}{\param{bool}{ flag}} | |
96 | ||
cc81d32f | 97 | If set to true data stored in hash table will be deleted when hash table object |
84b63045 VS |
98 | is destroyed. |
99 | ||
100 | ||
f0e8a2d0 | 101 | \membersection{wxHashTable::Get}\label{wxhashtableget} |
a660d684 KB |
102 | |
103 | \func{wxObject *}{Get}{\param{long}{ key}} | |
104 | ||
f6bcfd97 | 105 | \func{wxObject *}{Get}{\param{const char*}{ key}} |
a660d684 KB |
106 | |
107 | Gets data from the hash table, using an integer or string key (depending on which | |
108 | has table constructor was used). | |
109 | ||
f0e8a2d0 | 110 | \membersection{wxHashTable::MakeKey}\label{wxhashtablemakekey} |
a660d684 KB |
111 | |
112 | \func{long}{MakeKey}{\param{const wxString\& }{string}} | |
113 | ||
114 | Makes an integer key out of a string. An application may wish to make a key | |
115 | explicitly (for instance when combining two data values to form a key). | |
116 | ||
f0e8a2d0 | 117 | \membersection{wxHashTable::Next}\label{wxhashtablenext} |
a660d684 | 118 | |
7057f62a | 119 | \func{wxHashTable::Node *}{Next}{\void} |
a660d684 KB |
120 | |
121 | If the application wishes to iterate through all the data in the hash | |
122 | table, it can call {\it BeginFind} and then loop on {\it Next}. This function | |
7057f62a MB |
123 | returns a {\bf wxHashTable::Node} pointer (or NULL if there are no more nodes). |
124 | The return value is functionally equivalent to \textbf{wxNode} but might not be | |
125 | implemented as a \textbf{wxNode}. The user will probably only wish to use the | |
126 | \textbf{GetData} method to retrieve the data; the node may also be deleted. | |
a660d684 | 127 | |
f0e8a2d0 | 128 | \membersection{wxHashTable::Put}\label{wxhashtableput} |
a660d684 KB |
129 | |
130 | \func{void}{Put}{\param{long}{ key}, \param{wxObject *}{object}} | |
131 | ||
f6bcfd97 | 132 | \func{void}{Put}{\param{const char*}{ key}, \param{wxObject *}{object}} |
a660d684 KB |
133 | |
134 | Inserts data into the hash table, using an integer or string key (depending on which | |
135 | has table constructor was used). The key string is copied and stored by the hash | |
136 | table implementation. | |
137 | ||
f0e8a2d0 | 138 | \membersection{wxHashTable::GetCount}\label{wxhashtablegetcount} |
8bf9e177 BJ |
139 | |
140 | \constfunc{size\_t}{GetCount}{\void} | |
141 | ||
142 | Returns the number of elements in the hash table. | |
143 |