]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/hash.tex
added and documented wxDir::HasFiles/SubDirs(), use the latter in wxDirDialog - it...
[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
84b63045
VS
86\membersection{wxHashTable::DeleteContents}
87
88\func{void}{DeleteContents}{\param{bool}{ flag}}
89
90If set to TRUE data stored in hash table will be deleted when hash table object
91is destroyed.
92
93
a660d684
KB
94\membersection{wxHashTable::Get}
95
96\func{wxObject *}{Get}{\param{long}{ key}}
97
f6bcfd97 98\func{wxObject *}{Get}{\param{const char*}{ key}}
a660d684
KB
99
100Gets data from the hash table, using an integer or string key (depending on which
101has table constructor was used).
102
103\membersection{wxHashTable::MakeKey}
104
105\func{long}{MakeKey}{\param{const wxString\& }{string}}
106
107Makes an integer key out of a string. An application may wish to make a key
108explicitly (for instance when combining two data values to form a key).
109
110\membersection{wxHashTable::Next}
111
112\func{wxNode *}{Next}{\void}
113
114If the application wishes to iterate through all the data in the hash
115table, it can call {\it BeginFind} and then loop on {\it Next}. This function
116returns a {\bf wxNode} pointer (or NULL if there are no more nodes). See the
117description for \helpref{wxNode}{wxnode}. The user will probably only wish to use the
118{\bf wxNode::Data} function to retrieve the data; the node may also be deleted.
119
120\membersection{wxHashTable::Put}
121
122\func{void}{Put}{\param{long}{ key}, \param{wxObject *}{object}}
123
f6bcfd97 124\func{void}{Put}{\param{const char*}{ key}, \param{wxObject *}{object}}
a660d684
KB
125
126Inserts data into the hash table, using an integer or string key (depending on which
127has table constructor was used). The key string is copied and stored by the hash
128table implementation.
129
8bf9e177
BJ
130\membersection{wxList::GetCount}
131
132\constfunc{size\_t}{GetCount}{\void}
133
134Returns the number of elements in the hash table.
135