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
}
13 Below is an example of using a hash table.
16 wxHashTable table(KEY_STRING);
18 wxPoint *point = new wxPoint(
100,
200);
19 table.Put("point
1", point);
23 wxPoint *found_point = (wxPoint *)table.Get("point
1");
26 A hash table is implemented as an array of pointers to lists. When no
27 data has been stored, the hash table takes only a little more space than
28 this array (default size is
1000). When a data item is added, an
29 integer is constructed from the integer or string key that is within the
30 bounds of the array. If the array element is NULL, a new (keyed) list is
31 created for the element. Then the data object is appended to the list,
32 storing the key in case other data objects need to be stored in the list
33 also (when a `collision' occurs).
35 Retrieval involves recalculating the array index from the key, and searching
36 along the keyed list for the data object whose stored key matches the passed
37 key. Obviously this is quicker when there are fewer collisions, so hashing
38 will become inefficient if the number of items to be stored greatly exceeds
39 the size of the hash table.
43 \helpref{wxList
}{wxlist
}
45 \latexignore{\rtfignore{\wxheading{Members
}}}
47 \membersection{wxHashTable::wxHashTable
}
49 \func{}{wxHashTable
}{\param{unsigned int
}{ key
\_type},
\param{int
}{ size =
1000}}
51 Constructor.
{\it key
\_type} is one of wxKEY
\_INTEGER, or wxKEY
\_STRING,
52 and indicates what sort of keying is required.
{\it size
} is optional.
54 \membersection{wxHashTable::
\destruct{wxHashTable
}}
56 \func{}{\destruct{wxHashTable
}}{\void}
58 Destroys the hash table.
60 \membersection{wxHashTable::BeginFind
}
62 \func{void
}{BeginFind
}{\void}
64 The counterpart of
{\it Next
}. If the application wishes to iterate
65 through all the data in the hash table, it can call
{\it BeginFind
} and
66 then loop on
{\it Next
}.
68 \membersection{wxHashTable::Clear
}
70 \func{void
}{Clear
}{\void}
72 Clears the hash table of all nodes (but as usual, doesn't delete user data).
74 \membersection{wxHashTable::Delete
}
76 \func{wxObject *
}{Delete
}{\param{long
}{ key
}}
78 \func{wxObject *
}{Delete
}{\param{const wxString\&
}{ key
}}
80 Deletes entry in hash table and returns the user's data (if found).
82 \membersection{wxHashTable::Get
}
84 \func{wxObject *
}{Get
}{\param{long
}{ key
}}
86 \func{wxObject *
}{Get
}{\param{const wxString\&
}{ key
}}
88 Gets data from the hash table, using an integer or string key (depending on which
89 has table constructor was used).
91 \membersection{wxHashTable::MakeKey
}
93 \func{long
}{MakeKey
}{\param{const wxString\&
}{string
}}
95 Makes an integer key out of a string. An application may wish to make a key
96 explicitly (for instance when combining two data values to form a key).
98 \membersection{wxHashTable::Next
}
100 \func{wxNode *
}{Next
}{\void}
102 If the application wishes to iterate through all the data in the hash
103 table, it can call
{\it BeginFind
} and then loop on
{\it Next
}. This function
104 returns a
{\bf wxNode
} pointer (or NULL if there are no more nodes). See the
105 description 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.
108 \membersection{wxHashTable::Put
}
110 \func{void
}{Put
}{\param{long
}{ key
},
\param{wxObject *
}{object
}}
112 \func{void
}{Put
}{\param{const wxString\&
}{ key
},
\param{wxObject *
}{object
}}
114 Inserts data into the hash table, using an integer or string key (depending on which
115 has table constructor was used). The key string is copied and stored by the hash
116 table implementation.