From cae4b8d111277145e517e2e2ec98ec713dcb68b3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorsten=20Wi=C3=9Fmann?= <edu@thorsten-wissmann.de>
Date: Tue, 28 Jan 2014 16:16:13 +0100
Subject: [PATCH] Normalize agent list

---
 CoolUtils.ml  | 13 ++++++++++++-
 CoolUtils.mli |  1 +
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/CoolUtils.ml b/CoolUtils.ml
index bcd5043..13d5ed5 100644
--- a/CoolUtils.ml
+++ b/CoolUtils.ml
@@ -11,10 +11,21 @@ module TArray = struct
         any (fun y -> x == y) arr
     let included sub sup = all (fun x -> elem x sup) sub
     let to_string ts arr = "[| " ^ (Array.fold_right (fun i str -> (ts i) ^" "^ str) arr "|]")
+    let uniq arr =
+        let combine n l =
+            match l with
+            | [] -> [n]
+            | m::tail -> if n == m then l else n::l
+        in
+        Array.of_list (Array.fold_right combine arr [])
 end
 
 let agents = ref ([|1;2;3;4;5;6;7;8;9;10|])
 
 let cl_get_agents () = !agents
-let cl_set_agents arr = ignore (agents := arr)
+let cl_set_agents arr = ignore (
+    agents := arr;
+    Array.fast_sort compare !agents;
+    agents := TArray.uniq !agents)
+
 
diff --git a/CoolUtils.mli b/CoolUtils.mli
index bc2dfe9..f0f0605 100644
--- a/CoolUtils.mli
+++ b/CoolUtils.mli
@@ -7,6 +7,7 @@ module TArray : sig
     val elem : 'a -> 'a array -> bool
     val included : 'a array -> 'a array -> bool
     val to_string : ('a -> string) -> 'a array -> string
+    val uniq : 'a array -> 'a array (* delete consecutive duplicates *)
 end
 
 val cl_get_agents : unit -> int array
-- 
GitLab