diff options
author | Mike Buland <eichlan@xagasoft.com> | 2008-09-15 20:03:56 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2008-09-15 20:03:56 +0000 |
commit | 597a1487c716b799428f4b4a4903e65df4c93ba9 (patch) | |
tree | c743b0d4dfc3bacbffc196589543ec4e9abf1aaf /src/hash.h | |
parent | 3c6cb7f2347aed974543f9082a0ccd297577db41 (diff) | |
download | libbu++-597a1487c716b799428f4b4a4903e65df4c93ba9.tar.gz libbu++-597a1487c716b799428f4b4a4903e65df4c93ba9.tar.bz2 libbu++-597a1487c716b799428f4b4a4903e65df4c93ba9.tar.xz libbu++-597a1487c716b799428f4b4a4903e65df4c93ba9.zip |
Whoa! Loads of NIDS work. It actually compiles, runs, and I'm optimizing the
hell out of it. Good times, everyone. This is a major chunk for congo, and
the new optimizations should be good.
Diffstat (limited to 'src/hash.h')
-rw-r--r-- | src/hash.h | 50 |
1 files changed, 49 insertions, 1 deletions
@@ -16,6 +16,7 @@ | |||
16 | #include <utility> | 16 | #include <utility> |
17 | #include "bu/exceptionbase.h" | 17 | #include "bu/exceptionbase.h" |
18 | #include "bu/list.h" | 18 | #include "bu/list.h" |
19 | #include "bu/util.h" | ||
19 | ///#include "archival.h" | 20 | ///#include "archival.h" |
20 | ///#include "archive.h" | 21 | ///#include "archive.h" |
21 | 22 | ||
@@ -97,6 +98,7 @@ namespace Bu | |||
97 | * Direct function for retrieving a value out of the HashProxy. | 98 | * Direct function for retrieving a value out of the HashProxy. |
98 | *@returns (value_type &) The value pointed to by this HashProxy. | 99 | *@returns (value_type &) The value pointed to by this HashProxy. |
99 | */ | 100 | */ |
101 | DEPRECATED | ||
100 | _value &value() | 102 | _value &value() |
101 | { | 103 | { |
102 | if( bFilled == false ) | 104 | if( bFilled == false ) |
@@ -106,6 +108,20 @@ namespace Bu | |||
106 | ); | 108 | ); |
107 | return *pValue; | 109 | return *pValue; |
108 | } | 110 | } |
111 | |||
112 | /** | ||
113 | * Direct function for retrieving a value out of the HashProxy. | ||
114 | *@returns (value_type &) The value pointed to by this HashProxy. | ||
115 | */ | ||
116 | _value &getValue() | ||
117 | { | ||
118 | if( bFilled == false ) | ||
119 | throw HashException( | ||
120 | excodeNotFilled, | ||
121 | "No data assosiated with that key." | ||
122 | ); | ||
123 | return *pValue; | ||
124 | } | ||
109 | 125 | ||
110 | /** | 126 | /** |
111 | * Whether this HashProxy points to something real or not. | 127 | * Whether this HashProxy points to something real or not. |
@@ -165,7 +181,39 @@ namespace Bu | |||
165 | }; | 181 | }; |
166 | 182 | ||
167 | /** | 183 | /** |
168 | * Libbu Template Hash Table | 184 | * Libbu++ Template Hash Table. This is your average hash table, that uses |
185 | * template functions in order to do fast, efficient, generalized hashing. | ||
186 | * It's pretty easy to use, and works well with all other libbu++ types so | ||
187 | * far. | ||
188 | * | ||
189 | * In order to use it, I recommend the following for all basic usage: | ||
190 | *@code | ||
191 | // Define a Hash typedef with strings as keys and ints as values. | ||
192 | typedef Bu::Hash<Bu::FString, int> StrIntHash; | ||
193 | |||
194 | // Create one | ||
195 | StrIntHash hInts; | ||
196 | |||
197 | // Insert some integers | ||
198 | hInts["one"] = 1; | ||
199 | hInts["forty-two"] = 42; | ||
200 | hInts.insert("forty two", 42 ); | ||
201 | |||
202 | // Get values out of the hash, the last two options are the most explicit, | ||
203 | // and must be used if the hash's value type does not match what you're | ||
204 | // comparing to exactly. | ||
205 | if( hInts["one"] == 1 ) doSomething(); | ||
206 | if( hInts["forty-two"].value() == 42 ) doSomething(); | ||
207 | if( hInts.get("forty two") == 42 ) doSomething(); | ||
208 | |||
209 | // Iterate through the Hash | ||
210 | for( StrIntHash::iterator i = hInts.begin(); i != hInts.end(); i++ ) | ||
211 | { | ||
212 | // i.getValue() works too | ||
213 | print("'%s' = %d\n", i.getKey().getStr(), (*i) ); | ||
214 | } | ||
215 | |||
216 | @endcode | ||
169 | *@param key (typename) The datatype of the hashtable keys | 217 | *@param key (typename) The datatype of the hashtable keys |
170 | *@param value (typename) The datatype of the hashtable data | 218 | *@param value (typename) The datatype of the hashtable data |
171 | *@param sizecalc (typename) Functor to compute new table size on rehash | 219 | *@param sizecalc (typename) Functor to compute new table size on rehash |