diff options
author | Daniil Baturin <daniil@baturin.org> | 2015-04-23 08:22:39 +0600 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2015-04-23 08:22:39 +0600 |
commit | 187d282353d74d185d4b1bbe4ce69bc1b2948aa9 (patch) | |
tree | 8c644f30311cbb6f7c25fb3bc23380535e989435 /src | |
parent | ccab6d041c7ca307486bb344dd2a4e669e9bb9fe (diff) | |
download | vyconf-187d282353d74d185d4b1bbe4ce69bc1b2948aa9.tar.gz vyconf-187d282353d74d185d4b1bbe4ce69bc1b2948aa9.zip |
Add get_existent_path for finding the part of a path that already exists in a tree.
Diffstat (limited to 'src')
-rw-r--r-- | src/vytree.ml | 11 | ||||
-rw-r--r-- | src/vytree.mli | 2 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/vytree.ml b/src/vytree.ml index 10ccf0e..3177e24 100644 --- a/src/vytree.ml +++ b/src/vytree.ml @@ -92,3 +92,14 @@ let rec get node path = | [] -> raise Empty_path | [name] -> find_or_fail node name | name :: names -> get (find_or_fail node name) names + +let get_existent_path node path = + let rec aux node path acc = + match path with + | [] -> acc + | name :: names -> + let child = find node name in + match child with + | None -> acc + | Some c -> aux c names (name :: acc) + in List.rev (aux node path []) diff --git a/src/vytree.mli b/src/vytree.mli index 8224fdd..2ce7a36 100644 --- a/src/vytree.mli +++ b/src/vytree.mli @@ -25,3 +25,5 @@ val update : 'a t -> string list -> 'a -> 'a t val list_children : 'a t -> string list val get : 'a t -> string list -> 'a t + +val get_existent_path : 'a t -> string list -> string list |