summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2015-04-24 11:16:49 +0600
committerDaniil Baturin <daniil@baturin.org>2015-04-24 11:16:49 +0600
commitf6fad748cd5e68c36d4ed55e76c020d10d9bb7bd (patch)
treecc74a8a55d2863b869c0fb1068a5f7b8d683425e /src
parenta15396525e442acc76cca061e0cbe1bc98af83d0 (diff)
downloadvyconf-f6fad748cd5e68c36d4ed55e76c020d10d9bb7bd.tar.gz
vyconf-f6fad748cd5e68c36d4ed55e76c020d10d9bb7bd.zip
Add Vylist.complement for calculating difference between two lists
where one contains another (starting with the first element).
Diffstat (limited to 'src')
-rw-r--r--src/vylist.ml11
-rw-r--r--src/vylist.mli1
2 files changed, 12 insertions, 0 deletions
diff --git a/src/vylist.ml b/src/vylist.ml
index ec04055..f18801e 100644
--- a/src/vylist.ml
+++ b/src/vylist.ml
@@ -27,3 +27,14 @@ let rec insert_after p x xs =
| [] -> raise Not_found
| y :: ys -> if (p y) then y :: x :: ys
else y :: (insert_after p x ys)
+
+let complement xs ys =
+ let rec aux xs ys =
+ match xs, ys with
+ | [], _ -> Some ys
+ | _, [] -> assert false (* Can't happen *)
+ | p :: ps, q :: qs -> if p = q then aux ps qs
+ else None
+ in
+ if List.length xs < List.length ys then aux xs ys
+ else aux ys xs
diff --git a/src/vylist.mli b/src/vylist.mli
index 70f0042..9a713b3 100644
--- a/src/vylist.mli
+++ b/src/vylist.mli
@@ -3,3 +3,4 @@ val remove : ('a -> bool) -> 'a list -> 'a list
val replace : ('a -> bool) -> 'a -> 'a list -> 'a list
val insert_before : ('a -> bool) -> 'a -> 'a list -> 'a list
val insert_after : ('a -> bool) -> 'a -> 'a list -> 'a list
+val complement : 'a list -> 'a list -> 'a list option