caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Julien SIGNOLES <julien.signoles@cea.fr>
To: Alexy Khrabrov <deliverable@gmail.com>
Cc: OCaml <caml-list@inria.fr>
Subject: Re: [Caml-list] changing labels on ocamlgraph edges
Date: Thu, 12 Mar 2009 08:55:49 +0100	[thread overview]
Message-ID: <1236844549.22473.184.camel@localhost> (raw)
In-Reply-To: <5F21734C-C88E-4401-8EB4-811681A42E67@gmail.com>

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


  reply	other threads:[~2009-03-12  7:55 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-12  1:47 Alexy Khrabrov
2009-03-12  7:55 ` Julien SIGNOLES [this message]
2009-03-12 12:47   ` Re : [Caml-list] " Matthieu Wipliez
2009-03-12 14:38     ` Jean-Christophe Filliatre
2009-03-13  0:10       ` Alexy Khrabrov
2009-03-13 10:53         ` Re : " Matthieu Wipliez

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1236844549.22473.184.camel@localhost \
    --to=julien.signoles@cea.fr \
    --cc=caml-list@inria.fr \
    --cc=deliverable@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).