From 5f8b34c8aff9e256f61cf9ebf4f6935a92e3b92d Mon Sep 17 00:00:00 2001
From: Sebastien Ferre
Date: Mon, 21 May 2012 15:45:17 +0000
Subject: [PATCH] Add of 'partition_set'. Git.
---
lSet.ml | 39 ++++++++++++++++++++++-----------------
1 file changed, 22 insertions(+), 17 deletions(-)
diff --git a/lSet.ml b/lSet.ml
index 919276b..14a010c 100644
--- a/lSet.ml
+++ b/lSet.ml
@@ -1,4 +1,9 @@
-(** Sets as ordered polymorphic lists. *)
+(**
+ Sets as ordered polymorphic lists.
+
+ Author: S-Aébastien Ferré-b
+ License: LGPL
+*)
include List
@@ -120,22 +125,22 @@ let subtract_r : 'a list -> 'a list list -> 'a list =
let remove : 'a -> 'a list -> 'a list =
fun x l -> subtract l [x]
-(* partition par the belonging to a set *)
+(* partition by the belonging to a set *)
(* partitioner -> partitionee -> inter * diff *)
- let rec partition_set : 'a t -> 'a t -> 'a t * 'a t =
- fun l1 l2 -> match l1, l2 with
- | [], l2 -> [], l2
- | _, [] -> [], []
- | x1::l1, x2::l2 ->
- let comp = compare x1 x2 in
- if comp < 0 then
- partition_set l1 (x2::l2)
- else if comp > 0 then
- let inter, diff = partition_set (x1::l1) l2 in
- inter, x2::diff
- else
- let inter, diff = partition_set l1 l2 in
- x2::inter, diff
+let rec partition_set : 'a t -> 'a t -> 'a t * 'a t =
+ fun l1 l2 -> match l1, l2 with
+ | [], l2 -> [], l2
+ | _, [] -> [], []
+ | x1::l1, x2::l2 ->
+ let comp = compare x1 x2 in
+ if comp < 0 then
+ partition_set l1 (x2::l2)
+ else if comp > 0 then
+ let inter, diff = partition_set (x1::l1) l2 in
+ inter, x2::diff
+ else
+ let inter, diff = partition_set l1 l2 in
+ x2::inter, diff
(** Remove an element if present, add it otherwise. *)
let rec flip : 'a -> 'a list -> 'a list =
@@ -164,5 +169,5 @@ let rec fold : ('b -> inwhich * 'a -> 'b) -> 'b -> 'a list -> 'a list -> 'b =
(*
- iterative functions on lists can also be applied, at least in some cases
+ iterative functions on lists can also be applied, provided they preserve the order of lists
*)
--
1.8.5.2