1 \section{\class{wxHashTable
}}\label{wxhashtable
}
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
7 \wxheading{Derived from
}
9 \helpref{wxObject
}{wxobject
}
11 \wxheading{Include files
}
17 Below is an example of using a hash table.
20 wxHashTable table(KEY_STRING);
22 wxPoint *point = new wxPoint(
100,
200);
23 table.Put("point
1", point);
27 wxPoint *found_point = (wxPoint *)table.Get("point
1");
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).
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.
47 \helpref{wxList
}{wxlist
}
49 \latexignore{\rtfignore{\wxheading{Members
}}}
51 \membersection{wxHashTable::wxHashTable
}
53 \func{}{wxHashTable
}{\param{unsigned int
}{ key
\_type},
\param{int
}{ size =
1000}}
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.
58 \membersection{wxHashTable::
\destruct{wxHashTable
}}
60 \func{}{\destruct{wxHashTable
}}{\void}
62 Destroys the hash table.
64 \membersection{wxHashTable::BeginFind
}
66 \func{void
}{BeginFind
}{\void}
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
}.
72 \membersection{wxHashTable::Clear
}
74 \func{void
}{Clear
}{\void}
76 Clears the hash table of all nodes (but as usual, doesn't delete user data).
78 \membersection{wxHashTable::Delete
}
80 \func{wxObject *
}{Delete
}{\param{long
}{ key
}}
82 \func{wxObject *
}{Delete
}{\param{const wxString\&
}{ key
}}
84 Deletes entry in hash table and returns the user's data (if found).
86 \membersection{wxHashTable::Get
}
88 \func{wxObject *
}{Get
}{\param{long
}{ key
}}
90 \func{wxObject *
}{Get
}{\param{const wxString\&
}{ key
}}
92 Gets data from the hash table, using an integer or string key (depending on which
93 has table constructor was used).
95 \membersection{wxHashTable::MakeKey
}
97 \func{long
}{MakeKey
}{\param{const wxString\&
}{string
}}
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).
102 \membersection{wxHashTable::Next
}
104 \func{wxNode *
}{Next
}{\void}
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.
112 \membersection{wxHashTable::Put
}
114 \func{void
}{Put
}{\param{long
}{ key
},
\param{wxObject *
}{object
}}
116 \func{void
}{Put
}{\param{const wxString\&
}{ key
},
\param{wxObject *
}{object
}}
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.