Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Canonical Set/Map datastructure?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-03-06 (09:53)
From: Berke Durak <berke.durak@e...>
Subject: Re: [Caml-list] Canonical Set/Map datastructure?
Berke Durak a écrit :
> The Map and Set modules use AVL trees which are efficient but not 
> canonical - a given
> set of elements can have more than one representation.  This means that 
> you cannot use
> ad hoc comparison on sets and maps, and this is why they are presented 
> as functors.
> Does anyone know if, in the many years that have passed since the 
> implementation of
> those fine modules, someone has invented a (functional) datastructure 
> that is as
> efficient while being canonic?
> That would permit polymorphic set and map modules that work correctly on 
> sets of sets, for
> instance.  Of course, the order induced on sets by the adhoc comparison 
> doesn't have to
> be a useful order; just being a good order would suffice.

Thanks for all your replies.

I did not know that Patricia trees were canonical.

However, the idea of combining hash-consing and Patricia trees, however
elegant, does not suit my problem.  Basically, you are cheating by using
an auxiliary data structure, the hashtable (which is also O(n^2) worst-case).

As I was improving my IO combinator library with sets and maps, the structures
need to be self-contained, and not need a description as a bitstring (which
could be done by using Marshal.to_string but I don't think the performance
would be there).  Maybe some wizardry relying on the physical representation
of objects would permit storage of arbitrary values in Patricia trees, but I
remain skeptical.