From: Dom Lachowicz (domlachowicz@yahoo.com)
Date: Mon Oct 06 2003 - 18:35:04 EDT
Robert,
On the whole, this patch looks good. That said, I
think that it adds too many lines - you basically end
up duplicating ::find_slot.
Can't we just implement one (UT_String) in terms of
the other (const char *)?
If you get that fixed up, please commit this. This
patch is much more to my liking.
Thanks,
Dom
--- Robert Wilhelm <robert.wilhelm@gmx.net> wrote:
> Hi dom,
> 
> here is my try to skip the UT_String constructor
> in UT_StringPtrMap::pick(const char *). This time
> I had to add some functions to ut_hash which take
> (char *)
> instead of UT_String.
> 
> Even a little bit faster than Johnny Lee´s patch.
> 
> Robert
> > 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 )
> +	  {
> 
=== message truncated ===
__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com
This archive was generated by hypermail 2.1.4 : Mon Oct 06 2003 - 18:51:03 EDT