Announcing E 0.8.4: The Birthday Release
Tyler Close
tyler@waterken.com
Fri, 28 May 1999 07:41:33 -0400
> >> Is there some semantic trouble we would get into by adding an
> >> 'implementsSameMapping' method (feel free to substitute a better name)
> >> to the table protocol?
> >
> >It would be hell on wheels to implement. If you want to do comparisons like
> >that you should be using a binary tree and not a hashtable.
>
> Wouldn't it just be (in pseudocode for two maps, A and B)
>
> if a count != B count
> return false
> foreach k in A keys
> if A[k] != B[k]
> return false
> return true
I may be misunderstanding, but I think your pseudocode implies computing the
hash code for every element. This is what I meant by hell to implement. There is
no way to do an element by element comparison between two hashtables since two
equal hashtables will have different orderings if their underlying array sizes
are not equal. Since these array sizes are dependent upon the insert/remove
history of the hashtable and not its current content, two equal hashtables very
likely do not use the same size of underlying array.
I am guessing you know the above and just don't care about the cost of computing
n hash codes. My point was only that this is an expensive == operation compared
to == on a binary tree. Binary trees are made for this type of operation,
hashtables are meant for single element lookup.
Tyler