mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 11:45:31 -05:00
sequence and CCMultiSet
This commit is contained in:
parent
89b2e525bc
commit
ff2ab244f5
2 changed files with 20 additions and 0 deletions
|
|
@ -25,6 +25,8 @@ for any direct, indirect, incidental, special, exemplary, or consequential
|
|||
|
||||
(** {1 Multiset} *)
|
||||
|
||||
type 'a sequence = ('a -> unit) -> unit
|
||||
|
||||
module type S = sig
|
||||
type elt
|
||||
type t
|
||||
|
|
@ -69,6 +71,10 @@ module type S = sig
|
|||
val of_list : elt list -> t
|
||||
|
||||
val to_list : t -> elt list
|
||||
|
||||
val to_seq : t -> elt sequence
|
||||
|
||||
val of_seq : elt sequence -> t
|
||||
end
|
||||
|
||||
module Make(O : Set.OrderedType) = struct
|
||||
|
|
@ -172,4 +178,12 @@ module Make(O : Set.OrderedType) = struct
|
|||
| _ -> n_cons (n-1) x (x::l)
|
||||
in
|
||||
fold m [] (fun acc n x -> n_cons n x acc)
|
||||
|
||||
let to_seq m k =
|
||||
M.iter (fun x n -> for _i = 1 to n do k x done) m
|
||||
|
||||
let of_seq seq =
|
||||
let m = ref empty in
|
||||
seq (fun x -> m := add !m x);
|
||||
!m
|
||||
end
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ for any direct, indirect, incidental, special, exemplary, or consequential
|
|||
|
||||
(** {1 Multiset} *)
|
||||
|
||||
type 'a sequence = ('a -> unit) -> unit
|
||||
|
||||
module type S = sig
|
||||
type elt
|
||||
type t
|
||||
|
|
@ -69,6 +71,10 @@ module type S = sig
|
|||
val of_list : elt list -> t
|
||||
|
||||
val to_list : t -> elt list
|
||||
|
||||
val to_seq : t -> elt sequence
|
||||
|
||||
val of_seq : elt sequence -> t
|
||||
end
|
||||
|
||||
module Make(O : Set.OrderedType) : S with type elt = O.t
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue