[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| 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. Regards, Nicolas Cannasse ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners