-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuncgraph.sig
111 lines (84 loc) · 3.05 KB
/
funcgraph.sig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
signature FUNCGRAPH=
sig
type nodeID
type 'a node
type 'a edge = {from: nodeID, to: nodeID}
type 'a graph
exception NoSuchNode of nodeID
exception NoSuchEdge of nodeID * nodeID
val empty: 'a graph
(* add a node*)
val addNode: 'a graph * nodeID * 'a -> 'a graph
(* add a node, and return it immediately w/ the new graph*)
val addNode': 'a graph * nodeID * 'a -> 'a graph * 'a node
(* remove a node (and all of its edges).
* raises NoSuchNode(nodeId) if not present
*)
val removeNode: 'a graph * nodeID -> 'a graph
(* remove a node (and all of its edges).
* Returns graph unchanged if node is not present
*)
val removeNode': 'a graph * nodeID -> 'a graph
val remove : 'a graph * 'a node -> 'a graph
(* get a particular node, raises NoSuchNode if not found*)
val getNode: 'a graph * nodeID -> 'a node
(* pull the info out of the node *)
val nodeInfo: 'a node -> 'a
(* Add an edge. Raises
* NoSuchNode if either node is not in the graph
*)
val addEdge: 'a graph * 'a edge -> 'a graph
(*
* Add a doubly linked edge to the graph
*)
val doubleEdge : 'a graph * nodeID * nodeID -> 'a graph
(* remove an edge. raises NoSuchNode if the specified
* nodes do not exists, or NoSuchEdge if the edge does not exist
*)
val removeEdge: 'a graph * 'a edge -> 'a graph
(* remove an edge. If the edge does not
* exist, ignores it an returns the graph unchanged.
* If the nodes involved do not exists, throws NoSuchNode
*)
val removeEdge': 'a graph * 'a edge -> 'a graph
(* update the data associated with a node (keeping the edges the same)
* raises NoSuchNode if the node does not exist
*)
val changeNodeData: 'a graph * nodeID * 'a -> 'a graph
(* accessors*)
(* get all the nodes---these dont come in any particularly
* useful graph order
*)
val nodes: 'a graph -> 'a node list
(* get all of the successors of the nodes *)
val succs: 'a node -> nodeID list
val succs': 'a graph -> 'a node -> 'a node list
(* get all of the predecessors of the nodes *)
val preds: 'a node -> nodeID list
val preds': 'a graph -> 'a node -> 'a node list
(* get all of the adjacent nodes of the nodes *)
val adj: 'a node -> nodeID list
val adj': 'a graph -> 'a node -> 'a node list
(* Convert a node to a node id*)
val getNodeID: 'a node -> nodeID
(* how many successors? *)
val outDegree: 'a node -> int
(* how many predecessors? *)
val inDegree: 'a node -> int
(* How many edges *)
val degree: 'a node -> int
(* fold functions functions *)
val foldNodes: (('a node * 'b) -> 'b) -> 'b -> 'a graph -> 'b
val foldSuccs: ((nodeID * 'b) -> 'b) -> 'b -> 'a node -> 'b
val foldSuccs':'a graph -> (('a node * 'b) -> 'b) -> 'b -> 'a node -> 'b
val foldPreds: ((nodeID * 'b) -> 'b) -> 'b -> 'a node -> 'b
val foldPreds':'a graph -> (('a node * 'b) -> 'b) -> 'b -> 'a node -> 'b
val isAdjacent: 'a node * 'a node -> bool
(* debugging*)
(* print the graph. Give it a function
* that says how to convert any given node's data into a
* string, and it will print everything out
*)
val printGraph: ((nodeID * 'a) -> string) -> 'a graph -> unit
val printBiGraph: ((nodeID * 'a) -> string) -> 'a graph -> unit
end