summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2015-02-26 08:30:28 +0600
committerDaniil Baturin <daniil@baturin.org>2015-02-26 08:30:28 +0600
commit7364faa7d1273e3bfa6703780a659ec9adbf797c (patch)
treec41a6872abf8ad07abd0c340f000567a51d017f5
parent2931947e68415fdc163f4f38e0be61d42237a632 (diff)
downloadvyconf-7364faa7d1273e3bfa6703780a659ec9adbf797c.tar.gz
vyconf-7364faa7d1273e3bfa6703780a659ec9adbf797c.zip
Add delete_child function.
-rw-r--r--src/vytree.ml14
-rw-r--r--src/vytree.mli2
2 files changed, 16 insertions, 0 deletions
diff --git a/src/vytree.ml b/src/vytree.ml
index 22b4a6d..3b6819f 100644
--- a/src/vytree.ml
+++ b/src/vytree.ml
@@ -45,6 +45,10 @@ let insert_immediate_child node name data =
let children' = node.children @ [new_node] in
{ node with children = children' }
+let delete_immediate_child node name =
+ let children' = remove_child_from_list node.children name in
+ { node with children = children' }
+
let adopt_child node child =
{ node with children = (node.children @ [child]) }
@@ -79,3 +83,13 @@ let rec insert_child default_data node path data =
let next_child' = make name default_data in
let new_node = insert_child default_data next_child' names data in
adopt_child node new_node
+
+let rec delete_child node path =
+ match path with
+ | [] -> raise Empty_path
+ | [name] -> delete_immediate_child node name
+ | name :: names ->
+ let next_child = find_child node name in
+ match next_child with
+ | None -> raise Nonexistent_path
+ | Some next_child' -> delete_child next_child' names
diff --git a/src/vytree.mli b/src/vytree.mli
index dc14b1c..1b42de7 100644
--- a/src/vytree.mli
+++ b/src/vytree.mli
@@ -14,4 +14,6 @@ val children_of_node : 'a t -> 'a t list
val insert_child :
'a -> 'a t -> string list -> 'a -> 'a t
+val delete_child : 'a t -> string list -> 'a t
+
val list_children : 'a t -> string list