mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-07 19:55:31 -05:00
add CCHash.{list,array}_comm
This commit is contained in:
parent
8ddacbb028
commit
f1459b57df
2 changed files with 19 additions and 0 deletions
|
|
@ -56,6 +56,15 @@ let if_ b then_ else_ h =
|
||||||
|
|
||||||
let poly x = Hashtbl.hash x
|
let poly x = Hashtbl.hash x
|
||||||
|
|
||||||
|
let array_comm f a =
|
||||||
|
let arr = Array.init (Array.length a) (fun i -> f a.(i)) in
|
||||||
|
Array.sort CCInt.compare arr; (* sort the hashes, so their order does not matter *)
|
||||||
|
array (fun h->h) arr
|
||||||
|
|
||||||
|
let list_comm f l =
|
||||||
|
let a = Array.of_list l in
|
||||||
|
array_comm f a
|
||||||
|
|
||||||
let seq f seq =
|
let seq f seq =
|
||||||
let h = ref 0x43 in
|
let h = ref 0x43 in
|
||||||
seq (fun x -> h := combine f !h x);
|
seq (fun x -> h := combine f !h x);
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,16 @@ val if_ : bool -> 'a t -> 'a t -> 'a t
|
||||||
val poly : 'a t
|
val poly : 'a t
|
||||||
(** the regular polymorphic hash function *)
|
(** the regular polymorphic hash function *)
|
||||||
|
|
||||||
|
val list_comm : 'a t -> 'a list t
|
||||||
|
(** Commutative version of {!list}. Lists that are equal up to permutation
|
||||||
|
will have the same hash.
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
|
val array_comm : 'a t -> 'a array t
|
||||||
|
(** Commutative version of {!array}. Arrays that are equal up to permutation
|
||||||
|
will have the same hash.
|
||||||
|
@since NEXT_RELEASE *)
|
||||||
|
|
||||||
(** {2 Base hash combinators} *)
|
(** {2 Base hash combinators} *)
|
||||||
|
|
||||||
val combine : 'a t -> hash -> 'a -> hash
|
val combine : 'a t -> hash -> 'a -> hash
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue