unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* set operations ontop of vhashes
@ 2015-05-02  8:23 Stefan Israelsson Tampe
  0 siblings, 0 replies; only message in thread
From: Stefan Israelsson Tampe @ 2015-05-02  8:23 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 1403 bytes --]

Hi all,

I just added set datastructures for guile-log. I realized that I could
implement those for guile as well.
The algorithm is plain in that it adds an extra fields 'size and hashvalue
to the vhash struct so

at unification
Use the largest set as a base and add the extra elements from the other one
ontop of this.
hash -> hash(x) xor h
n -> n + 1

at intersection
Use the smallest hash as a base and delete the arguments that is not in
both by simply add a delete
value to the vhash.
hash -> hash(x) xor h
n -> n - 1

and likewise for set difference.

the logic for equivalent is
(cond
   ((not (= nx ny))           #f)
   ((nat (= hashx hashy) #f)
   (else
       direct check)

The trick is to detect when size(vhash) > 2*n after each operation in in
such cases just create a new vhash where deleted elements are removed.

+ subset and superset operators as well as.

This interface depends on a functional hash, we know that vhashes in guile
is not thread safe so we might want other such datastructures in the
future, I will make the setup as a module
set-generic, with a macro that if applied generate the interface assuming
hash-cons hash-assoc vlist-null and will define the operators regarding
those, I will then add a vhash-sets and clos-sets as interfaces that use
that, I would suggest the namespace
(ice-9 set *) for the datastructure.

WDYT, do we need this in guile?

Regards
Stefan

[-- Attachment #2: Type: text/html, Size: 1880 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-05-02  8:23 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-02  8:23 set operations ontop of vhashes Stefan Israelsson Tampe

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