]>
Commit | Line | Data |
---|---|---|
1 | \section{\class{wxHashTable}}\label{wxhashtable} | |
2 | ||
3 | This class provides hash table functionality for wxWindows, and for an | |
4 | application if it wishes. Data can be hashed on an integer or string | |
5 | key. | |
6 | ||
7 | \wxheading{Derived from} | |
8 | ||
9 | \helpref{wxObject}{wxobject} | |
10 | ||
11 | \wxheading{Example} | |
12 | ||
13 | Below is an example of using a hash table. | |
14 | ||
15 | \begin{verbatim} | |
16 | wxHashTable table(KEY_STRING); | |
17 | ||
18 | wxPoint *point = new wxPoint(100, 200); | |
19 | table.Put("point 1", point); | |
20 | ||
21 | .... | |
22 | ||
23 | wxPoint *found_point = (wxPoint *)table.Get("point 1"); | |
24 | \end{verbatim} | |
25 | ||
26 | A hash table is implemented as an array of pointers to lists. When no | |
27 | data has been stored, the hash table takes only a little more space than | |
28 | this array (default size is 1000). When a data item is added, an | |
29 | integer is constructed from the integer or string key that is within the | |
30 | bounds of the array. If the array element is NULL, a new (keyed) list is | |
31 | created for the element. Then the data object is appended to the list, | |
32 | storing the key in case other data objects need to be stored in the list | |
33 | also (when a `collision' occurs). | |
34 | ||
35 | Retrieval involves recalculating the array index from the key, and searching | |
36 | along the keyed list for the data object whose stored key matches the passed | |
37 | key. Obviously this is quicker when there are fewer collisions, so hashing | |
38 | will become inefficient if the number of items to be stored greatly exceeds | |
39 | the size of the hash table. | |
40 | ||
41 | \wxheading{See also} | |
42 | ||
43 | \helpref{wxList}{wxlist} | |
44 | ||
45 | \latexignore{\rtfignore{\wxheading{Members}}} | |
46 | ||
47 | \membersection{wxHashTable::wxHashTable} | |
48 | ||
49 | \func{}{wxHashTable}{\param{unsigned int}{ key\_type}, \param{int}{ size = 1000}} | |
50 | ||
51 | Constructor. {\it key\_type} is one of wxKEY\_INTEGER, or wxKEY\_STRING, | |
52 | and indicates what sort of keying is required. {\it size} is optional. | |
53 | ||
54 | \membersection{wxHashTable::\destruct{wxHashTable}} | |
55 | ||
56 | \func{}{\destruct{wxHashTable}}{\void} | |
57 | ||
58 | Destroys the hash table. | |
59 | ||
60 | \membersection{wxHashTable::BeginFind} | |
61 | ||
62 | \func{void}{BeginFind}{\void} | |
63 | ||
64 | The counterpart of {\it Next}. If the application wishes to iterate | |
65 | through all the data in the hash table, it can call {\it BeginFind} and | |
66 | then loop on {\it Next}. | |
67 | ||
68 | \membersection{wxHashTable::Clear} | |
69 | ||
70 | \func{void}{Clear}{\void} | |
71 | ||
72 | Clears the hash table of all nodes (but as usual, doesn't delete user data). | |
73 | ||
74 | \membersection{wxHashTable::Delete} | |
75 | ||
76 | \func{wxObject *}{Delete}{\param{long}{ key}} | |
77 | ||
78 | \func{wxObject *}{Delete}{\param{const wxString\& }{ key}} | |
79 | ||
80 | Deletes entry in hash table and returns the user's data (if found). | |
81 | ||
82 | \membersection{wxHashTable::Get} | |
83 | ||
84 | \func{wxObject *}{Get}{\param{long}{ key}} | |
85 | ||
86 | \func{wxObject *}{Get}{\param{const wxString\& }{ key}} | |
87 | ||
88 | Gets data from the hash table, using an integer or string key (depending on which | |
89 | has table constructor was used). | |
90 | ||
91 | \membersection{wxHashTable::MakeKey} | |
92 | ||
93 | \func{long}{MakeKey}{\param{const wxString\& }{string}} | |
94 | ||
95 | Makes an integer key out of a string. An application may wish to make a key | |
96 | explicitly (for instance when combining two data values to form a key). | |
97 | ||
98 | \membersection{wxHashTable::Next} | |
99 | ||
100 | \func{wxNode *}{Next}{\void} | |
101 | ||
102 | If the application wishes to iterate through all the data in the hash | |
103 | table, it can call {\it BeginFind} and then loop on {\it Next}. This function | |
104 | returns a {\bf wxNode} pointer (or NULL if there are no more nodes). See the | |
105 | description for \helpref{wxNode}{wxnode}. The user will probably only wish to use the | |
106 | {\bf wxNode::Data} function to retrieve the data; the node may also be deleted. | |
107 | ||
108 | \membersection{wxHashTable::Put} | |
109 | ||
110 | \func{void}{Put}{\param{long}{ key}, \param{wxObject *}{object}} | |
111 | ||
112 | \func{void}{Put}{\param{const wxString\& }{ key}, \param{wxObject *}{object}} | |
113 | ||
114 | Inserts data into the hash table, using an integer or string key (depending on which | |
115 | has table constructor was used). The key string is copied and stored by the hash | |
116 | table implementation. | |
117 | ||
118 |