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