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: Julien SIGNOLES <julien.signoles@c...>
Subject: Re: [Caml-list] changing labels on ocamlgraph edges
Hello,

> 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 = 
  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)

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