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
[Caml-list] sharing problem ...
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-01-26 (11:17)
From: Nicolas Cannasse <warplayer@f...>
Subject: Re: [Caml-list] sharing problem ...
> Hi all,
> I'm trying to implement a (string * set) hashtbl
> where some element (set) should be shared between different
> objects.
> the main point is that when I clone an object I want to duplicate
> some sets and shared others (sticky sets)
> I tried to achieve this result with the method below.
> it use the set_copy to duplicate a set and does nothing when then
> element is marked as "shared".
> how can I efficiently share elements in this kind of structure ?

The main problem is that you're comparing the sets based on a structural
polymorphic equality (compare) while what you want/need is physical
comparison, which is of course faster and is the only way to detect shared
structures. Sadly, there is no :  phys_compare : 'a -> 'a -> int  in OCaml,
so you might use the following method :

Add an unique integer "id" to your set in a record, that will enable you to
maintain a hashtbl (or set) of shared structures based on integer comparison
between their id's. That's what OCaml is doing inside the compiler.

Nicolas Cannasse

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: