summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2015-03-28 06:25:58 +0600
committerDaniil Baturin <daniil@baturin.org>2015-03-28 06:25:58 +0600
commit3a5148b6535d2446be0b7fc3599fd668d927409b (patch)
tree7f439546e1be965c7f3e3a33c3f31cdc867bd40e /src
parent8855202f9ee4769b20d36cda8d0e4e20b9c31a2d (diff)
downloadvyconf-3a5148b6535d2446be0b7fc3599fd668d927409b.tar.gz
vyconf-3a5148b6535d2446be0b7fc3599fd668d927409b.zip
Add insert_before and insert_after functions to Vylist.
They will be used in node reordering.
Diffstat (limited to 'src')
-rw-r--r--src/vylist.ml12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/vylist.ml b/src/vylist.ml
index c6a1044..9afea5f 100644
--- a/src/vylist.ml
+++ b/src/vylist.ml
@@ -15,3 +15,15 @@ let rec replace p x xs =
| [] -> []
| x' :: xs' -> if (p x') then x :: xs'
else x' :: (replace p x xs')
+
+let rec insert_before p x xs =
+ match xs with
+ | [] -> raise Not_found
+ | y :: ys -> if (p y) then x :: y :: ys
+ else y :: (insert_before p x ys)
+
+let rec insert_after p x xs =
+ match xs with
+ | [] -> raise Not_found
+ | y :: ys -> if (p y) then y :: x :: ys
+ else y :: (insert_after p x ys)