diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/vytree.ml | 26 | ||||
-rw-r--r-- | src/vytree.mli | 2 |
2 files changed, 11 insertions, 17 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 diff --git a/src/vytree.mli b/src/vytree.mli index cebbcde..8224fdd 100644 --- a/src/vytree.mli +++ b/src/vytree.mli @@ -16,7 +16,7 @@ val name_of_node : 'a t -> string val data_of_node : 'a t -> 'a val children_of_node : 'a t -> 'a t list -val insert : 'a t -> string list -> 'a list -> 'a t +val insert : 'a t -> string list -> 'a -> 'a t val delete : 'a t -> string list -> 'a t |