summaryrefslogtreecommitdiff
path: root/src/vytree.ml
diff options
context:
space:
mode:
Diffstat (limited to 'src/vytree.ml')
-rw-r--r--src/vytree.ml26
1 files changed, 10 insertions, 16 deletions
diff --git a/src/vytree.ml b/src/vytree.ml
index 728e26d..10ccf0e 100644
--- a/src/vytree.ml
+++ b/src/vytree.ml
@@ -60,28 +60,22 @@ let rec do_with_child fn node path =
let new_node = do_with_child fn next_child names in
replace node new_node
-let rec insert node path data_list =
- match (path, data_list) with
- | ([], _) -> raise Empty_path
- | (_ :: _, []) -> raise (Insert_error "No data found")
- | ([name], [datum]) ->
- begin
- (* Check for duplicate item *)
- let last_child = find node name in
- match last_child with
- | None -> insert_immediate node name datum
- | (Some _) -> raise Duplicate_child
- end
- | (name :: names, datum :: data) ->
+let rec insert node path data =
+ match path with
+ | [] -> raise Empty_path
+ | [name] ->
+ (let last_child = find node name in
+ match last_child with
+ | None -> insert_immediate node name data
+ | (Some _) -> raise Duplicate_child)
+ | name :: names ->
let next_child = find node name in
match next_child with
| Some next_child' ->
let new_node = insert next_child' names data in
replace node new_node
| None ->
- let next_child' = make datum name in
- let new_node = insert next_child' names data in
- adopt node new_node
+ raise (Insert_error "Path does not exist")
let delete node path =
do_with_child delete_immediate node path