1 \section{\class{wxHashTable
}}\label{wxhashtable
}
3 {\bf Please note
} that this class is retained for backward compatibility
4 reasons; you should use
\helpref{wxHashMap
}{wxhashmap
}.
6 This class provides hash table functionality for wxWidgets, and for an
7 application if it wishes. Data can be hashed on an integer or string
10 \wxheading{Derived from
}
12 \helpref{wxObject
}{wxobject
}
14 \wxheading{Include files
}
20 Below is an example of using a hash table.
23 wxHashTable table(wxKEY_STRING);
25 wxPoint *point = new wxPoint(
100,
200);
26 table.Put("point
1", point);
30 wxPoint *found_point = (wxPoint *)table.Get("point
1");
33 A hash table is implemented as an array of pointers to lists. When no
34 data has been stored, the hash table takes only a little more space than
35 this array (default size is
1000). When a data item is added, an
36 integer is constructed from the integer or string key that is within the
37 bounds of the array. If the array element is NULL, a new (keyed) list is
38 created for the element. Then the data object is appended to the list,
39 storing the key in case other data objects need to be stored in the list
40 also (when a `collision' occurs).
42 Retrieval involves recalculating the array index from the key, and searching
43 along the keyed list for the data object whose stored key matches the passed
44 key. Obviously this is quicker when there are fewer collisions, so hashing
45 will become inefficient if the number of items to be stored greatly exceeds
46 the size of the hash table.
50 \helpref{wxList
}{wxlist
}
52 \latexignore{\rtfignore{\wxheading{Members
}}}
54 \membersection{wxHashTable::wxHashTable
}\label{wxhashtablector
}
56 \func{}{wxHashTable
}{\param{unsigned int
}{ key
\_type},
\param{int
}{ size =
1000}}
58 Constructor.
{\it key
\_type} is one of wxKEY
\_INTEGER, or wxKEY
\_STRING,
59 and indicates what sort of keying is required.
{\it size
} is optional.
61 \membersection{wxHashTable::
\destruct{wxHashTable
}}\label{wxhashtabledtor
}
63 \func{}{\destruct{wxHashTable
}}{\void}
65 Destroys the hash table.
67 \membersection{wxHashTable::BeginFind
}\label{wxhashtablebeginfind
}
69 \func{void
}{BeginFind
}{\void}
71 The counterpart of
{\it Next
}. If the application wishes to iterate
72 through all the data in the hash table, it can call
{\it BeginFind
} and
73 then loop on
{\it Next
}.
75 \membersection{wxHashTable::Clear
}\label{wxhashtableclear
}
77 \func{void
}{Clear
}{\void}
79 Clears the hash table of all nodes (but as usual, doesn't delete user data).
81 \membersection{wxHashTable::Delete
}\label{wxhashtabledelete
}
83 \func{wxObject *
}{Delete
}{\param{long
}{ key
}}
85 \func{wxObject *
}{Delete
}{\param{const wxString\&
}{ key
}}
87 Deletes entry in hash table and returns the user's data (if found).
89 \membersection{wxHashTable::DeleteContents
}\label{wxhashtabledeletecontents
}
91 \func{void
}{DeleteContents
}{\param{bool
}{ flag
}}
93 If set to true data stored in hash table will be deleted when hash table object
97 \membersection{wxHashTable::Get
}\label{wxhashtableget
}
99 \func{wxObject *
}{Get
}{\param{long
}{ key
}}
101 \func{wxObject *
}{Get
}{\param{const char*
}{ key
}}
103 Gets data from the hash table, using an integer or string key (depending on which
104 has table constructor was used).
106 \membersection{wxHashTable::MakeKey
}\label{wxhashtablemakekey
}
108 \func{long
}{MakeKey
}{\param{const wxString\&
}{string
}}
110 Makes an integer key out of a string. An application may wish to make a key
111 explicitly (for instance when combining two data values to form a key).
113 \membersection{wxHashTable::Next
}\label{wxhashtablenext
}
115 \func{wxHashTable::Node *
}{Next
}{\void}
117 If the application wishes to iterate through all the data in the hash
118 table, it can call
{\it BeginFind
} and then loop on
{\it Next
}. This function
119 returns a
{\bf wxHashTable::Node
} pointer (or NULL if there are no more nodes).
120 The return value is functionally equivalent to
\textbf{wxNode
} but might not be
121 implemented as a
\textbf{wxNode
}. The user will probably only wish to use the
122 \textbf{GetData
} method to retrieve the data; the node may also be deleted.
124 \membersection{wxHashTable::Put
}\label{wxhashtableput
}
126 \func{void
}{Put
}{\param{long
}{ key
},
\param{wxObject *
}{object
}}
128 \func{void
}{Put
}{\param{const char*
}{ key
},
\param{wxObject *
}{object
}}
130 Inserts data into the hash table, using an integer or string key (depending on which
131 has table constructor was used). The key string is copied and stored by the hash
132 table implementation.
134 \membersection{wxHashTable::GetCount
}\label{wxhashtablegetcount
}
136 \constfunc{size
\_t}{GetCount
}{\void}
138 Returns the number of elements in the hash table.