aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPierre-Marie Pédrot2014-07-21 19:38:55 +0200
committerPierre-Marie Pédrot2014-07-21 19:40:18 +0200
commit5519c14ed70d231d369e56b0792e6c43423bae10 (patch)
tree6541f52940f5fa843c4bf3ba631244dbf7d64b7c /lib
parentc4ecec191130a51975bf97d067472e0e5bd744f5 (diff)
Missing primitives in HMap.
Diffstat (limited to 'lib')
-rw-r--r--lib/hMap.ml26
1 files changed, 20 insertions, 6 deletions
diff --git a/lib/hMap.ml b/lib/hMap.ml
index ea70e152df..d66db21a6e 100644
--- a/lib/hMap.ml
+++ b/lib/hMap.ml
@@ -79,7 +79,7 @@ struct
let inter s1 s2 =
let fu _ m1 m2 = match m1, m2 with
| None, None -> None
- | (Some _ as m), None | None, (Some _ as m) -> None
+ | Some _, None | None, Some _ -> None
| Some m1, Some m2 ->
let m = Set.inter m1 m2 in
if Set.is_empty m then None else Some m
@@ -90,7 +90,7 @@ struct
let fu _ m1 m2 = match m1, m2 with
| None, None -> None
| (Some _ as m), None -> m
- | None, (Some _ as m) -> None
+ | None, Some _ -> None
| Some m1, Some m2 ->
let m = Set.diff m1 m2 in
if Set.is_empty m then None else Some m
@@ -129,7 +129,14 @@ struct
let s = Int.Map.map ff s in
Int.Map.filter (fun _ m -> not (Set.is_empty m)) s
- let partition f s = assert false (** TODO *)
+ let partition f s =
+ let fold h m (sl, sr) =
+ let (ml, mr) = Set.partition f m in
+ let sl = if Set.is_empty ml then sl else Int.Map.add h ml sl in
+ let sr = if Set.is_empty mr then sr else Int.Map.add h mr sr in
+ (sl, sr)
+ in
+ Int.Map.fold fold s (Int.Map.empty, Int.Map.empty)
let cardinal s =
let fold _ m accu = accu + Set.cardinal m in
@@ -147,7 +154,7 @@ struct
let (_, m) = Int.Map.choose s in
Set.choose m
- let split s x = assert false
+ let split s x = assert false (** Cannot be implemented efficiently *)
end
@@ -245,7 +252,14 @@ struct
let s = Int.Map.map ff s in
Int.Map.filter (fun _ m -> not (Map.is_empty m)) s
- let partition f s = assert false (** TODO *)
+ let partition f s =
+ let fold h m (sl, sr) =
+ let (ml, mr) = Map.partition f m in
+ let sl = if Map.is_empty ml then sl else Int.Map.add h ml sl in
+ let sr = if Map.is_empty mr then sr else Int.Map.add h mr sr in
+ (sl, sr)
+ in
+ Int.Map.fold fold s (Int.Map.empty, Int.Map.empty)
let cardinal s =
let fold _ m accu = accu + Map.cardinal m in
@@ -272,7 +286,7 @@ struct
let m = Int.Map.find h s in
Map.find k m
- let split k s = assert false (** TODO *)
+ let split k s = assert false (** Cannot be implemented efficiently *)
let map f s =
let fs m = Map.map f m in