From 597a1487c716b799428f4b4a4903e65df4c93ba9 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 15 Sep 2008 20:03:56 +0000 Subject: 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. --- src/hash.h | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'src/hash.h') diff --git a/src/hash.h b/src/hash.h index 30ad256..25dc509 100644 --- a/src/hash.h +++ b/src/hash.h @@ -16,6 +16,7 @@ #include #include "bu/exceptionbase.h" #include "bu/list.h" +#include "bu/util.h" ///#include "archival.h" ///#include "archive.h" @@ -97,6 +98,7 @@ namespace Bu * Direct function for retrieving a value out of the HashProxy. *@returns (value_type &) The value pointed to by this HashProxy. */ + DEPRECATED _value &value() { if( bFilled == false ) @@ -106,6 +108,20 @@ namespace Bu ); return *pValue; } + + /** + * Direct function for retrieving a value out of the HashProxy. + *@returns (value_type &) The value pointed to by this HashProxy. + */ + _value &getValue() + { + if( bFilled == false ) + throw HashException( + excodeNotFilled, + "No data assosiated with that key." + ); + return *pValue; + } /** * Whether this HashProxy points to something real or not. @@ -165,7 +181,39 @@ namespace Bu }; /** - * Libbu Template Hash Table + * Libbu++ Template Hash Table. This is your average hash table, that uses + * template functions in order to do fast, efficient, generalized hashing. + * It's pretty easy to use, and works well with all other libbu++ types so + * far. + * + * In order to use it, I recommend the following for all basic usage: + *@code + // Define a Hash typedef with strings as keys and ints as values. + typedef Bu::Hash StrIntHash; + + // Create one + StrIntHash hInts; + + // Insert some integers + hInts["one"] = 1; + hInts["forty-two"] = 42; + hInts.insert("forty two", 42 ); + + // Get values out of the hash, the last two options are the most explicit, + // and must be used if the hash's value type does not match what you're + // comparing to exactly. + if( hInts["one"] == 1 ) doSomething(); + if( hInts["forty-two"].value() == 42 ) doSomething(); + if( hInts.get("forty two") == 42 ) doSomething(); + + // Iterate through the Hash + for( StrIntHash::iterator i = hInts.begin(); i != hInts.end(); i++ ) + { + // i.getValue() works too + print("'%s' = %d\n", i.getKey().getStr(), (*i) ); + } + + @endcode *@param key (typename) The datatype of the hashtable keys *@param value (typename) The datatype of the hashtable data *@param sizecalc (typename) Functor to compute new table size on rehash -- cgit v1.2.3