|
@@ -1,10 +1,24 @@
|
|
|
(* Mesh = Zusammenhangskomponente eines einfachen Graphen *)
|
|
|
|
|
|
-(* XXX Unterschiedliche key Typen (statt beide = int)
|
|
|
- für die Maps node2meshindex und meshes
|
|
|
- um Verwechslungen durch den type checker zu erkennen *)
|
|
|
+signature MESH =
|
|
|
+sig
|
|
|
+ structure Key : ORD_KEY
|
|
|
+ structure Set : ORD_SET
|
|
|
+ structure PairSet : ORD_SET
|
|
|
+ structure Map : ORD_MAP
|
|
|
|
|
|
-structure Mesh =
|
|
|
+ type mesh = { nodes : Set.set,
|
|
|
+ edges : PairSet.set }
|
|
|
+ type meshes = mesh Map.map
|
|
|
+ type graph = { meshes : meshes,
|
|
|
+ node2meshindex : Key.ord_key Map.map }
|
|
|
+
|
|
|
+ val empty_graph : graph
|
|
|
+ val add_link : graph -> int * int -> graph
|
|
|
+ val links2graph : (int * int) list -> graph
|
|
|
+end
|
|
|
+
|
|
|
+structure Mesh : MESH =
|
|
|
struct
|
|
|
|
|
|
functor PairKeyFn ( Key : ORD_KEY ) : ORD_KEY =
|
|
@@ -21,27 +35,32 @@ struct
|
|
|
end
|
|
|
end
|
|
|
|
|
|
+ (* XXX Unterschiedliche key Typen (statt beide = int)
|
|
|
+ fuer die Maps node2meshindex und meshes
|
|
|
+ damit der type checker Verwechslungen erkennen kann *)
|
|
|
+
|
|
|
structure Key =
|
|
|
struct
|
|
|
- type ord_key = Int.int
|
|
|
- val compare = Int.compare
|
|
|
- val minkey = 0
|
|
|
- fun nextkey k = k + 1
|
|
|
+ type ord_key = Int.int
|
|
|
+ val compare = Int.compare
|
|
|
+ val minkey = 0
|
|
|
+ fun nextkey k = k + 1
|
|
|
end
|
|
|
|
|
|
structure PairKey = PairKeyFn (Key)
|
|
|
|
|
|
- structure Set = SplaySetFn (Key)
|
|
|
+ structure Set = SplaySetFn (Key)
|
|
|
structure PairSet = SplaySetFn (PairKey)
|
|
|
- structure Map = SplayMapFn (Key)
|
|
|
+ structure Map = SplayMapFn (Key)
|
|
|
|
|
|
- type mesh = { nodes : Set.set,
|
|
|
- edges : PairSet.set }
|
|
|
- type meshes = mesh Map.map
|
|
|
- type graph = { meshes : meshes,
|
|
|
- node2meshindex : Key.ord_key Map.map }
|
|
|
+ type mesh = { nodes : Set.set,
|
|
|
+ edges : PairSet.set }
|
|
|
+ type meshes = mesh Map.map
|
|
|
+ type graph = { meshes : meshes,
|
|
|
+ node2meshindex : Key.ord_key Map.map }
|
|
|
|
|
|
- val empty = { meshes = Map.empty, node2meshindex = Map.empty }
|
|
|
+ val empty_graph = { meshes = Map.empty,
|
|
|
+ node2meshindex = Map.empty }
|
|
|
|
|
|
fun n2im (g : graph) n =
|
|
|
case Map.find (#node2meshindex g, n)
|
|
@@ -114,4 +133,8 @@ struct
|
|
|
then (n2, n1) else e
|
|
|
in add_link' g (na, nb)
|
|
|
end
|
|
|
+
|
|
|
+ fun links2graph links = foldl (fn (e, g) => add_link g e)
|
|
|
+ empty_graph
|
|
|
+ links
|
|
|
end
|