K
Ken Durden
Look at this code for simply managing a count field in a hashtable.
public void Increment( EStuff e )
{
object obCurrentCount = m_hash[e];
// If its not in there yet, then add it as one and skip the
increment
if( obCurrentCount == null )
obCurrentCount = m_hash[e] = 1;
// Increment it
else
m_hash[e] = ((int) obCurrentCount) + 1;
}
Note that each access into the hashtable actually involves two
hashtable lookups. I've actually considered creating my own class-type
with reference semantics to wrap around the 'int' type (like Java's
Integer) class.
Anyone know of an existing implementation of a reference-based Integer
class? I'm not particularly concerned with efficiency in this case,
but I would guess that using a reference Integer class would be more
effecient than all the excessive boxing, unboxing, and hashtable
lookups that are required in this solution.
Thanks,
-ken
public void Increment( EStuff e )
{
object obCurrentCount = m_hash[e];
// If its not in there yet, then add it as one and skip the
increment
if( obCurrentCount == null )
obCurrentCount = m_hash[e] = 1;
// Increment it
else
m_hash[e] = ((int) obCurrentCount) + 1;
}
Note that each access into the hashtable actually involves two
hashtable lookups. I've actually considered creating my own class-type
with reference semantics to wrap around the 'int' type (like Java's
Integer) class.
Anyone know of an existing implementation of a reference-based Integer
class? I'm not particularly concerned with efficiency in this case,
but I would guess that using a reference Integer class would be more
effecient than all the excessive boxing, unboxing, and hashtable
lookups that are required in this solution.
Thanks,
-ken