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
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: 2009-03-12 (07:55)
From: Julien SIGNOLES <julien.signoles@c...>
Subject: Re: [Caml-list] changing labels on ocamlgraph edges

> It looks like the only way to change a label on an edge e -- say  
> increment it -- is to read off the old one with G.E.label, then  
> remember the src and dst with G.E.src/dst, then G.remove_edge_e g e,  
> create a new edge e' with G.V.create src (label+1) dst, and  
> G.add_adge_e g e'.  Is this supposed to be so complicated even for the  
> imperative graphs?

No it is not :-). You just have to define yourself a mutable label. Here
is an example.

open Graph

module G = 
    (struct include String let equal = (=) let hash = Hashtbl.hash end)
       type t = int ref 
       let default = ref 0 
       let compare =

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