Index: ut_hash.cpp =================================================================== RCS file: /cvsroot/abi/src/af/util/xp/ut_hash.cpp,v retrieving revision 1.39 diff -u -r1.39 ut_hash.cpp --- ut_hash.cpp 13 Jul 2003 10:08:24 -0000 1.39 +++ ut_hash.cpp 6 Oct 2003 21:28:40 -0000 @@ -44,6 +44,11 @@ { return (m_val == key); } + + bool eq(const char *key) const + { + return (!strcmp(m_val.c_str(),key)); + } void operator=(const UT_String &k) { m_val = k; } @@ -64,6 +69,11 @@ return hashcode(key); // UT_String::hashcode } + static UT_uint32 compute_hash(const char *key) + { + return hashcode(key); + } + private: UT_String m_val; UT_uint32 m_hashval; @@ -117,7 +127,16 @@ return m_key.hashval() == h; #endif } - + + bool key_eq(const char *test, size_t h) const + { +#if 1 + return m_key.eq(test); +#else + return m_key.hashval() == h; +#endif + } + const void* m_value; key_wrapper m_key; }; @@ -184,12 +203,6 @@ */ const void* UT_StringPtrMap::pick(const char* k) const { - UT_String aKey(k); - return pick (aKey); -} - -const void* UT_StringPtrMap::pick(const UT_String & k) const -{ hash_slot* sl = 0; bool key_found = false; size_t slot; @@ -199,6 +212,11 @@ return key_found ? sl->value() : 0; } +const void* UT_StringPtrMap::pick(const UT_String & k) const +{ + return pick (k.c_str()); +} + /*! * See if the map contains the (key, value) pair represented by (\k, \v) * If \v is null, just see if the key \k exists @@ -457,6 +475,127 @@ int nSlot = hashval % m_nSlots; xxx_UT_DEBUGMSG(("DOM: hashval for \"%s\" is %d (#%dth slot)\n", k.c_str(), hashval, nSlot)); + + hash_slot* sl = &m_pMapping[nSlot]; + + if (sl->empty()) + { + + xxx_UT_DEBUGMSG(("DOM: empty slot\n")); + + slot = nSlot; + key_found = false; + return sl; + } + else + { + if (search_type != SM_REORG && + !sl->deleted() && + sl->key_eq(k, hashval)) + { + slot = nSlot; + key_found = true; + + if (v_found) + { + // so, if v_found is non-null, we should set it. + // if v is also non-null, sl->value() must match v + // otherwise we already have a key match, so we win! + if (v) + { + *v_found = (sl->value() == v); + } else { + *v_found = true; + } + } + + xxx_UT_DEBUGMSG(("DOM: found something #1\n")); + + return sl; + } + } + + int delta = (nSlot ? (m_nSlots - nSlot) : 1); + hash_slot* tmp_sl = sl; + sl = 0; + size_t s = 0; + key_found = false; + + while (1) + { + nSlot -= delta; + if (nSlot < 0) + { + nSlot += m_nSlots; + tmp_sl += (m_nSlots - delta); + } + else + { + tmp_sl -= delta; + } + + if (tmp_sl->empty()) + { + if (!s) + { + s = nSlot; + sl = tmp_sl; + } + break; + + } + + if (tmp_sl->deleted()) + { + if (!s) + { + s = nSlot; + sl = tmp_sl; + } + } + else if (search_type != SM_REORG && tmp_sl->key_eq(k, hashval)) + { + s = nSlot; + sl = tmp_sl; + key_found = true; + + if (v_found) + { + if (v) + { + *v_found = (sl->value() == v); + } else { + *v_found = true; + } + } + break; + } + } + + slot = s; + return sl; +} + +hash_slot* +UT_StringPtrMap::find_slot(const char *k, + SM_search_type search_type, + size_t& slot, + bool& key_found, + size_t& hashval, + const void* v, + bool* v_found, + void* vi, + size_t hashval_in) const +{ + if ( m_nSlots == 0 ) + { + key_found = false ; return NULL ; + } + + hashval = (hashval_in ? hashval_in : key_wrapper::compute_hash(k)); + int nSlot = hashval % m_nSlots; + + xxx_UT_DEBUGMSG(("DOM: hashval for \"%s\" is %d (#%dth slot)\n", k, hashval, nSlot)); hash_slot* sl = &m_pMapping[nSlot]; Index: ut_hash.h =================================================================== RCS file: /cvsroot/abi/src/af/util/xp/ut_hash.h,v retrieving revision 1.26 diff -u -r1.26 ut_hash.h --- ut_hash.h 13 Jul 2003 10:08:24 -0000 1.26 +++ ut_hash.h 6 Oct 2003 21:28:41 -0000 @@ -149,6 +149,16 @@ bool* v_found, void* vi, size_t hashval_in) const; + + hash_slot* find_slot(const char * k, + SM_search_type search_type, + size_t& slot, + bool& key_found, + size_t& hashval, + const void* v, + bool* v_found, + void* vi, + size_t hashval_in) const; // enumeration of the elements const void* _first(UT_Cursor& c) const; Index: ut_string_class.cpp =================================================================== RCS file: /cvsroot/abi/src/af/util/xp/ut_string_class.cpp,v retrieving revision 1.53 diff -u -r1.53 ut_string_class.cpp --- ut_string_class.cpp 28 Aug 2003 05:50:00 -0000 1.53 +++ ut_string_class.cpp 6 Oct 2003 21:28:42 -0000 @@ -700,7 +700,12 @@ UT_uint32 hashcode(const UT_String& string) { // from glib - const char* p = string.c_str(); + return hashcode(string.c_str()); +} + +UT_uint32 hashcode(const char *p) +{ + // from glib UT_uint32 h = (UT_uint32)*p; if (h) Index: ut_string_class.h =================================================================== RCS file: /cvsroot/abi/src/af/util/xp/ut_string_class.h,v retrieving revision 1.40 diff -u -r1.40 ut_string_class.h --- ut_string_class.h 2 Sep 2003 19:10:54 -0000 1.40 +++ ut_string_class.h 6 Oct 2003 21:28:43 -0000 @@ -112,6 +112,7 @@ ABI_EXPORT bool operator!=(const char* s1, const UT_String& s2); ABI_EXPORT UT_uint32 hashcode(const UT_String& string); +ABI_EXPORT UT_uint32 hashcode(const char *s); // strcmp ordering ABI_EXPORT bool operator<(const UT_String& s1, const UT_String& s2);