unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Aleksandar Sandic <asflin@gmx.de>
To: Mark H Weaver <mhw@netris.org>
Cc: guile-user@gnu.org
Subject: Re: Comparing two hash tables for equality?
Date: Mon, 27 Aug 2018 23:53:09 +0200	[thread overview]
Message-ID: <21644757.cYmYgW3VaQ@aleksandar-ixtreme-m5740> (raw)
In-Reply-To: <87o9dovj4z.fsf@netris.org>

> 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.





  parent reply	other threads:[~2018-08-27 21:53 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-26 10:01 Comparing two hash tables for equality? Aleksandar Sandic
2018-08-26 22:49 ` Mark H Weaver
2018-08-26 23:37   ` John Cowan
2018-08-27 22:14     ` Aleksandar Sandic
2018-08-29  4:46       ` Mark H Weaver
2018-08-27 20:25   ` Arne Babenhauserheide
2018-08-27 21:53   ` Aleksandar Sandic [this message]
2018-08-28  7:37     ` Mark H Weaver

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=21644757.cYmYgW3VaQ@aleksandar-ixtreme-m5740 \
    --to=asflin@gmx.de \
    --cc=guile-user@gnu.org \
    --cc=mhw@netris.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).