~ubuntu-branches/ubuntu/breezy/ocamlgraph/breezy

« back to all changes in this revision

Viewing changes to gmap.ml

  • Committer: Bazaar Package Importer
  • Author(s): Sylvain Le Gall
  • Date: 2005-03-23 23:17:46 UTC
  • mfrom: (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050323231746-8rmzgp3zyslg4me5
Tags: 0.90-2
* Transition to ocaml 3.08.3 : depends on ocaml-nox-3.08.3
* Patch 03_META use graph.cma and graph.cmxa ( Closes: #294806 )
* Correct the patch 01_makefile to install graph.a ( Closes: #289138 )

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(*
 
2
 * Graph: generic graph library
 
3
 * Copyright (C) 2004
 
4
 * Sylvain Conchon, Jean-Christophe Filliatre and Julien Signoles
 
5
 * 
 
6
 * This software is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU Library General Public
 
8
 * License version 2, as published by the Free Software Foundation.
 
9
 * 
 
10
 * This software is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
13
 * 
 
14
 * See the GNU Library General Public License version 2 for more details
 
15
 * (enclosed in the file LGPL).
 
16
 *)
 
17
 
 
18
(* $Id: gmap.ml,v 1.1 2004/10/20 09:59:56 signoles Exp $ *)
 
19
 
 
20
module Vertex
 
21
  (G_Init : sig
 
22
     type t
 
23
     module V : Sig.HASHABLE
 
24
     val fold_vertex : (V.t -> 'a -> 'a) -> t -> 'a -> 'a
 
25
   end)
 
26
  (G_Dest : sig
 
27
     type t
 
28
     type vertex
 
29
     val empty : unit -> t
 
30
     val add_vertex : t -> vertex -> t
 
31
   end) =
 
32
struct
 
33
  
 
34
  module H = Hashtbl.Make(G_Init.V)
 
35
    
 
36
  let vertices = H.create 97
 
37
 
 
38
  let convert_vertex f x =
 
39
    try 
 
40
      H.find vertices x
 
41
    with Not_found ->
 
42
      let x' = f x in
 
43
      H.add vertices x x';
 
44
      x'
 
45
 
 
46
  let map f g =
 
47
    H.clear vertices;
 
48
    G_Init.fold_vertex
 
49
      (fun x g -> G_Dest.add_vertex g (convert_vertex f x)) 
 
50
      g (G_Dest.empty ())
 
51
 
 
52
end
 
53
 
 
54
module Edge
 
55
  (G_Init : sig
 
56
     type t
 
57
     module E : Sig.HASHABLE
 
58
     val fold_edges_e : (E.t -> 'a -> 'a) -> t -> 'a -> 'a
 
59
   end)
 
60
  (G_Dest : sig
 
61
     type t
 
62
     type edge
 
63
     val empty : unit -> t
 
64
     val add_edge_e : t -> edge -> t
 
65
   end) =
 
66
  Vertex
 
67
    (struct include G_Init module V = E let fold_vertex = fold_edges_e end)
 
68
    (struct include G_Dest type vertex = edge let add_vertex = add_edge_e end)