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