package links
A few graph algorithms. Pure interfaces, but impure implementations. A graph is represented as node lists + adjacency list.
val hashfind_dflt : ('a, 'b) Links_core.Utility.Hashtbl.t -> 'a -> 'b -> 'b
Crazy notation for hashtable updates. Suggestions are welcomed.
table *->! k v
updates k to v in table table *-> k |-> d
returns the value for k
in table
, or d
if k
is not set. table *+> k ++= newVal
cons'es newVal onto the list stored under k
val (*->!) : ('a, 'b) Links_core.Utility.Hashtbl.t -> 'a -> 'b -> unit
val (*->) : ('a, 'b) Links_core.Utility.Hashtbl.t -> 'a -> 'b -> 'b
val (*+>) : ('a, 'b list) Links_core.Utility.Hashtbl.t -> 'a -> 'b -> unit
val hashtbl_invert :
('a, 'b) Links_core.Utility.Hashtbl.t ->
('b, 'a list) Links_core.Utility.Hashtbl.t
val hashtbl_values : ('a, 'b) Links_core.Utility.Hashtbl.t -> 'b list
val hashtbl_regions : ('a, 'b) Links_core.Utility.Hashtbl.t -> 'a list list
hashtbl_regions table
is the list of equivalence classes of keys in table
, where equivalence is determined through lookup in table
. If you think of the value under each key as its "color", this gives you the list of groups having the same color.
val hashtbl_as_alist : ('a, 'b) Links_core.Utility.Hashtbl.t -> ('a * 'b) list
unroll_edges: given an alist that maps an x to a list nbhd(x) of the same type, return a list of all the pairs (u, v) where v \in nbhd(u)
val dfs :
'a list ->
('a * 'a) list ->
('a, int) Links_core.Utility.Hashtbl.t
* ('a, int) Links_core.Utility.Hashtbl.t
* ('a, 'a option) Links_core.Utility.Hashtbl.t
Depth-first search
Takes a tree given in "parent-pointer" form, and returns a list of the nodes in each tree. More or less duplicates the union-find algorithm?