help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: Comparing lists


From: Michael Heerdegen
Subject: Re: Comparing lists
Date: Fri, 15 Sep 2023 04:12:42 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

Petteri Hintsanen <petterih@iki.fi> writes:

> seq-set-equal-p would fit the bill but does not seem to be recursive.
> For example:
>
>   (seq-set-equal-p '(a b (c d)) '(a b (d c))) ⇒ nil

I think there is nothing in Emacs that matches your case exactly.  The
map.el library comes close: your data has the form of nested
alists, i.e. nested maps, but there is no equality test for maps
implemented in that library.

Developers want to provide a "set.el" library in the future, but nobody
has started to write one so far.


If your data is always a nested alist with symbols as keys, I would try
to compare two data objects A and B efficiently like this:

 - if not both A and B are `consp', compare using `equal' (no need for a
  `proper-list-p' test I think)

 - if they are both `consp' sort the elements in A and B using the
   symbol names in the `car's as keys

 - then you can sequentially compare the alist elements: all `cars'
   should be `eq' and all `cdr's should be recursively equal, and no
   alist should run out of elements before the other also runs out of
   elements

If the data objects are really big, using hash tables might be better
than sorting.

Michael.



reply via email to

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