diff options
author | Daniil Baturin <daniil@baturin.org> | 2015-04-24 11:16:49 +0600 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2015-04-24 11:16:49 +0600 |
commit | f6fad748cd5e68c36d4ed55e76c020d10d9bb7bd (patch) | |
tree | cc74a8a55d2863b869c0fb1068a5f7b8d683425e /src/vylist.ml | |
parent | a15396525e442acc76cca061e0cbe1bc98af83d0 (diff) | |
download | vyconf-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/vylist.ml')
-rw-r--r-- | src/vylist.ml | 11 |
1 files changed, 11 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 |