]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/hash.tex
Doc updates.
[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::Get}
87
88 \func{wxObject *}{Get}{\param{long}{ key}}
89
90 \func{wxObject *}{Get}{\param{const wxString\& }{ key}}
91
92 Gets data from the hash table, using an integer or string key (depending on which
93 has table constructor was used).
94
95 \membersection{wxHashTable::MakeKey}
96
97 \func{long}{MakeKey}{\param{const wxString\& }{string}}
98
99 Makes an integer key out of a string. An application may wish to make a key
100 explicitly (for instance when combining two data values to form a key).
101
102 \membersection{wxHashTable::Next}
103
104 \func{wxNode *}{Next}{\void}
105
106 If the application wishes to iterate through all the data in the hash
107 table, it can call {\it BeginFind} and then loop on {\it Next}. This function
108 returns a {\bf wxNode} pointer (or NULL if there are no more nodes). See the
109 description 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
118 Inserts data into the hash table, using an integer or string key (depending on which
119 has table constructor was used). The key string is copied and stored by the hash
120 table implementation.
121
122