]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/hash.tex
minor clean up
[wxWidgets.git] / docs / latex / wx / hash.tex
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{Include files}
12
13 <wx/hash.h>
14
15 \wxheading{Example}
16
17 Below 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
30 A hash table is implemented as an array of pointers to lists. When no
31 data has been stored, the hash table takes only a little more space than
32 this array (default size is 1000). When a data item is added, an
33 integer is constructed from the integer or string key that is within the
34 bounds of the array. If the array element is NULL, a new (keyed) list is
35 created for the element. Then the data object is appended to the list,
36 storing the key in case other data objects need to be stored in the list
37 also (when a `collision' occurs).
38
39 Retrieval involves recalculating the array index from the key, and searching
40 along the keyed list for the data object whose stored key matches the passed
41 key. Obviously this is quicker when there are fewer collisions, so hashing
42 will become inefficient if the number of items to be stored greatly exceeds
43 the 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
55 Constructor. {\it key\_type} is one of wxKEY\_INTEGER, or wxKEY\_STRING,
56 and indicates what sort of keying is required. {\it size} is optional.
57
58 \membersection{wxHashTable::\destruct{wxHashTable}}
59
60 \func{}{\destruct{wxHashTable}}{\void}
61
62 Destroys the hash table.
63
64 \membersection{wxHashTable::BeginFind}
65
66 \func{void}{BeginFind}{\void}
67
68 The counterpart of {\it Next}. If the application wishes to iterate
69 through all the data in the hash table, it can call {\it BeginFind} and
70 then loop on {\it Next}.
71
72 \membersection{wxHashTable::Clear}
73
74 \func{void}{Clear}{\void}
75
76 Clears 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
84 Deletes entry in hash table and returns the user's data (if found).
85
86 \membersection{wxHashTable::DeleteContents}
87
88 \func{void}{DeleteContents}{\param{bool}{ flag}}
89
90 If set to TRUE data stored in hash table will be deleted when hash table object
91 is destroyed.
92
93
94 \membersection{wxHashTable::Get}
95
96 \func{wxObject *}{Get}{\param{long}{ key}}
97
98 \func{wxObject *}{Get}{\param{const char*}{ key}}
99
100 Gets data from the hash table, using an integer or string key (depending on which
101 has table constructor was used).
102
103 \membersection{wxHashTable::MakeKey}
104
105 \func{long}{MakeKey}{\param{const wxString\& }{string}}
106
107 Makes an integer key out of a string. An application may wish to make a key
108 explicitly (for instance when combining two data values to form a key).
109
110 \membersection{wxHashTable::Next}
111
112 \func{wxNode *}{Next}{\void}
113
114 If the application wishes to iterate through all the data in the hash
115 table, it can call {\it BeginFind} and then loop on {\it Next}. This function
116 returns a {\bf wxNode} pointer (or NULL if there are no more nodes). See the
117 description 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
124 \func{void}{Put}{\param{const char*}{ key}, \param{wxObject *}{object}}
125
126 Inserts data into the hash table, using an integer or string key (depending on which
127 has table constructor was used). The key string is copied and stored by the hash
128 table implementation.
129
130 \membersection{wxList::GetCount}
131
132 \constfunc{size\_t}{GetCount}{\void}
133
134 Returns the number of elements in the hash table.
135