File: wx110.htm

package info (click to toggle)
wxwin2-doc 2.01-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 6,540 kB
  • ctags: 5,968
  • sloc: cpp: 15,157; makefile: 434; sh: 6
file content (134 lines) | stat: -rw-r--r-- 5,249 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<HTML>
<head><title>wxHashTable</title></head>

<BODY BGCOLOR=#FFFFFF>
<A NAME="wxhashtable"></A><CENTER>
<A HREF="wx.htm"><img align=center src="contents.gif" BORDER=0 ALT="Contents"></A> <A HREF="wx22.htm#classref"><img align=center src="up.gif" BORDER=0 ALT="Up"></A> <A HREF="wx109.htm#wxgrid"><img align=center src="back.gif" BORDER=0 ALT="Previous"></A> <A HREF="wx111.htm#wxhelpcontroller"><img align=center src="forward.gif" BORDER=0 ALT="Next"></A> </CENTER><HR>

<H2>wxHashTable</H2>
<P>
This class provides hash table functionality for wxWindows, and for an
application if it wishes.  Data can be hashed on an integer or string
key.<P>
<B><FONT COLOR="#FF0000">Derived from</FONT></B><P>
<A HREF="wx158.htm#wxobject">wxObject</A><P>
<B><FONT COLOR="#FF0000">Include files</FONT></B><P>
&lt;wx/hash.h&gt;<P>
<B><FONT COLOR="#FF0000">Example</FONT></B><P>
Below is an example of using a hash table.<P>
<PRE>
  wxHashTable table(KEY_STRING);

  wxPoint *point = new wxPoint(100, 200);
  table.Put("point 1", point);

  ....

  wxPoint *found_point = (wxPoint *)table.Get("point 1");
</PRE>
A hash table is implemented as an array of pointers to lists. When no
data has been stored, the hash table takes only a little more space than
this array (default size is 1000).  When a data item is added, an
integer is constructed from the integer or string key that is within the
bounds of the array. If the array element is NULL, a new (keyed) list is
created for the element. Then the data object is appended to the list,
storing the key in case other data objects need to be stored in the list
also (when a 'collision' occurs).<P>
Retrieval involves recalculating the array index from the key, and searching
along the keyed list for the data object whose stored key matches the passed
key. Obviously this is quicker when there are fewer collisions, so hashing
will become inefficient if the number of items to be stored greatly exceeds
the size of the hash table.<P>
<B><FONT COLOR="#FF0000">See also</FONT></B><P>
<A HREF="wx127.htm#wxlist">wxList</A><P>
<B><FONT COLOR="#FF0000">Members</FONT></B><P>
<A HREF="#topic427">wxHashTable::wxHashTable</A><BR>
<A HREF="#topic428">wxHashTable::~wxHashTable</A><BR>
<A HREF="#topic429">wxHashTable::BeginFind</A><BR>
<A HREF="#topic430">wxHashTable::Clear</A><BR>
<A HREF="#topic431">wxHashTable::Delete</A><BR>
<A HREF="#topic432">wxHashTable::Get</A><BR>
<A HREF="#topic433">wxHashTable::MakeKey</A><BR>
<A HREF="#topic434">wxHashTable::Next</A><BR>
<A HREF="#topic435">wxHashTable::Put</A><BR>
<P>

<HR>
<A NAME="topic427"></A>
<H3>wxHashTable::wxHashTable</H3>
<P>
<B></B> <B>wxHashTable</B>(<B>unsigned int</B><I> key_type</I>, <B>int</B><I> size = 1000</I>)<P>
Constructor. <I>key_type</I> is one of wxKEY_INTEGER, or wxKEY_STRING,
and indicates what sort of keying is required. <I>size</I> is optional.<P>

<HR>
<A NAME="topic428"></A>
<H3>wxHashTable::~wxHashTable</H3>
<P>
<B></B> <B>~wxHashTable</B>()<P>
Destroys the hash table.<P>

<HR>
<A NAME="topic429"></A>
<H3>wxHashTable::BeginFind</H3>
<P>
<B>void</B> <B>BeginFind</B>()<P>
The counterpart of <I>Next</I>.  If the application wishes to iterate
through all the data in the hash table, it can call <I>BeginFind</I> and
then loop on <I>Next</I>.<P>

<HR>
<A NAME="topic430"></A>
<H3>wxHashTable::Clear</H3>
<P>
<B>void</B> <B>Clear</B>()<P>
Clears the hash table of all nodes (but as usual, doesn't delete user data).<P>

<HR>
<A NAME="topic431"></A>
<H3>wxHashTable::Delete</H3>
<P>
<B>wxObject *</B> <B>Delete</B>(<B>long</B><I> key</I>)<P>
<B>wxObject *</B> <B>Delete</B>(<B>const wxString&amp; </B><I> key</I>)<P>
Deletes entry in hash table and returns the user's data (if found).<P>

<HR>
<A NAME="topic432"></A>
<H3>wxHashTable::Get</H3>
<P>
<B>wxObject *</B> <B>Get</B>(<B>long</B><I> key</I>)<P>
<B>wxObject *</B> <B>Get</B>(<B>const wxString&amp; </B><I> key</I>)<P>
Gets data from the hash table, using an integer or string key (depending on which
has table constructor was used).<P>

<HR>
<A NAME="topic433"></A>
<H3>wxHashTable::MakeKey</H3>
<P>
<B>long</B> <B>MakeKey</B>(<B>const wxString&amp; </B><I>string</I>)<P>
Makes an integer key out of a string. An application may wish to make a key
explicitly (for instance when combining two data values to form a key).<P>

<HR>
<A NAME="topic434"></A>
<H3>wxHashTable::Next</H3>
<P>
<B>wxNode *</B> <B>Next</B>()<P>
If the application wishes to iterate through all the data in the hash
table, it can call <I>BeginFind</I> and then loop on <I>Next</I>. This function
returns a <B>wxNode</B> pointer (or NULL if there are no more nodes).  See the
description for <A HREF="wx155.htm#wxnode">wxNode</A>. The user will probably only wish to use the
<B>wxNode::Data</B> function to retrieve the data; the node may also be deleted.<P>

<HR>
<A NAME="topic435"></A>
<H3>wxHashTable::Put</H3>
<P>
<B>void</B> <B>Put</B>(<B>long</B><I> key</I>, <B>wxObject *</B><I>object</I>)<P>
<B>void</B> <B>Put</B>(<B>const wxString&amp; </B><I> key</I>, <B>wxObject *</B><I>object</I>)<P>
Inserts data into the hash table, using an integer or string key (depending on which
has table constructor was used). The key string is copied and stored by the hash
table implementation.<P>


</BODY></HTML>