guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Comparing two hash tables for equality?


From: Aleksandar Sandic
Subject: Re: Comparing two hash tables for equality?
Date: Mon, 27 Aug 2018 23:53:09 +0200

> An equality test on hash tables needs to know how to compare the keys
> and how to compare the values.  There's no way to pass those additional
> arguments to 'equal?', so it can't do that job.
It has to compare the values, but not the keys. If you take a look at my code, 
what it does is first compare the size of both tables; if it differs then the 
tables are not equal. If the number of entries is the same we can loop over 
the keys of one table and compare the corresponding values. If a key from 
table A is not present in table B, then the tables differ. Finally, if two 
values for a key are not 'equal?', then the tables differ as well.

> Hash table implementations typically don't offer an equality test on the
> hash tables themselves, and I don't recall anyone ever asking for such
> an operation before now.  I guess that's because in the use case where
> hash tables are beneficial -- when the tables are very large --
> comparing them for equality is expensive.
I was mostly interested in equality for writing unit tests, so in my case an 
equality test that's good enough for the job is adequate. It is not intended 
to be used in production code. I was just wondering if there might be a 
standard way instead of rolling my own.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]