summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2015-02-28 06:22:12 +0600
committerDaniil Baturin <daniil@baturin.org>2015-02-28 06:22:12 +0600
commit559715be78fdfa5d6f3a1756dfa0b8ebb7032228 (patch)
tree45bc05fa86e5e4eb4dca168d4520eb5c74df20e2
parentd32b48829184f54cee11856cff65b4c8d5122f97 (diff)
downloadvyconf-559715be78fdfa5d6f3a1756dfa0b8ebb7032228.tar.gz
vyconf-559715be78fdfa5d6f3a1756dfa0b8ebb7032228.zip
Fix the notion of duplicate child in insert_child.
Right now it doesn't compare data, but maybe it should.
-rw-r--r--src/vytree.ml12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/vytree.ml b/src/vytree.ml
index 1a380e3..af0dee0 100644
--- a/src/vytree.ml
+++ b/src/vytree.ml
@@ -71,14 +71,20 @@ let list_children node =
let rec insert_child default_data node path data =
match path with
| [] -> raise Empty_path
- | [name] -> insert_immediate_child node name data
+ | [name] ->
+ begin
+ (* Check for duplicate item *)
+ let last_child = find_child node name in
+ match last_child with
+ | None -> insert_immediate_child node name data
+ | (Some _) -> raise Duplicate_child
+ end
| name :: names ->
let next_child = find_child node name in
match next_child with
| Some next_child' ->
let new_node = insert_child default_data next_child' names data in
- if names = [] then raise Duplicate_child
- else replace_child node new_node
+ replace_child node new_node
| None ->
let next_child' = make name default_data in
let new_node = insert_child default_data next_child' names data in