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