Version française
Home     About     Download     Resources     Contact us    
Browse thread
changing labels on ocamlgraph edges
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Matthieu Wipliez <mwipliez@y...>
Subject: Re : [Caml-list] changing labels on ocamlgraph edges

> No it is not :-). You just have to define yourself a mutable label. Here
> is an example.
> 
> ==========
> open Graph
> 
> module G = 
>   Imperative.Digraph.ConcreteLabeled
>     (struct include String let equal = (=) let hash = Hashtbl.hash end)
>     (struct 
>        type t = int ref 
>        let default = ref 0 
>        let compare = Pervasives.compare
>      end)

I'm also using ocamlgraph with labels of type t = bool ref * int option
And I found that for add_edge to have the proper behavior, I need to replace the default add_edge with this one:
  let add_edge graph v1 v2 = add_edge_e graph (v1, (ref false, None), v2)

Otherwise all edges share the same reference (created in "default"), and changing the boolean for an edge changes it for all edges...

Cheers,
Matthieu

> 
> let g = G.create ()
> 
> let print_edge v1 v2 = 
>   Format.printf "edge = %d@." !(G.E.label (G.find_edge g v1 v2))
> 
> let e = G.E.create "foo" (ref 1) "bar"
> let () = 
>   G.add_edge_e g e;
>   print_edge "foo" "bar";
>   G.E.label e := 2;
>   print_edge "foo" "bar"
> ==========
> 
> Hope this helps,
> Julien Signoles
> 
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs