summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2015-04-23 08:22:39 +0600
committerDaniil Baturin <daniil@baturin.org>2015-04-23 08:22:39 +0600
commit187d282353d74d185d4b1bbe4ce69bc1b2948aa9 (patch)
tree8c644f30311cbb6f7c25fb3bc23380535e989435 /src
parentccab6d041c7ca307486bb344dd2a4e669e9bb9fe (diff)
downloadvyconf-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.ml11
-rw-r--r--src/vytree.mli2
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