Skip to content

Commit

Permalink
Merge 0596495 into 4d306ff
Browse files Browse the repository at this point in the history
  • Loading branch information
chenglou committed Mar 15, 2018
2 parents 4d306ff + 0596495 commit ce9ac60
Show file tree
Hide file tree
Showing 36 changed files with 906 additions and 735 deletions.
38 changes: 22 additions & 16 deletions jscomp/others/belt_HashMap.mli
Expand Up @@ -30,7 +30,7 @@
For example:
{[
type t = int
type t = int
module I0 =
(val Belt.Id.hashableU
~hash:(fun[\@bs] (a : t) -> a & 0xff_ff)
Expand Down Expand Up @@ -75,13 +75,13 @@ module Int = Belt_HashMapInt


(** Specalized when key type is [string], more efficient
than the gerneic type *)
than the gerneic type *)
module String = Belt_HashMapString




type ('key,'value,'id) t
type ('key,'value,'id) t
(** The type of hash tables from type ['key] to type ['value]. *)

type ('a, 'id) id = ('a, 'id) Belt_Id.hashable
Expand All @@ -93,32 +93,30 @@ val make: hintSize:int -> id:('key, 'id) id -> ('key,'value,'id) t
val clear: ('key, 'value, 'id ) t -> unit
(** Empty a hash table. *)

val isEmpty: _ t -> bool
val isEmpty: _ t -> bool

val set: ('key, 'value, 'id ) t -> 'key -> 'value -> unit
(** [set tbl k v] if [k] does not exist,
add the binding [k,v], otherwise, update the old value with the new
[v]
*)

val copy: ('key, 'value, 'id ) t -> ('key, 'value, 'id ) t

val get: ('key, 'value, 'id ) t -> 'key -> 'value option


val has: ('key, 'value, 'id ) t -> 'key -> bool
(** [has tbl x] checks if [x] is bound in [tbl]. *)

val remove: ('key, 'value, 'id ) t -> 'key -> unit

val forEachU: ('key, 'value, 'id ) t -> ('key -> 'value -> unit [@bs]) -> unit
val forEach: ('key, 'value, 'id ) t -> ('key -> 'value -> unit) -> unit
(** [forEach tbl f] applies [f] to all bindings in table [tbl].
[f] receives the key as first argument, and the associated value
as second argument. Each binding is presented exactly once to [f].
*)

val reduceU: ('key, 'value, 'id ) t -> 'c -> ('c -> 'key -> 'value -> 'c [@bs]) -> 'c
val reduce: ('key, 'value, 'id ) t -> 'c -> ('c -> 'key -> 'value -> 'c) -> 'c
(** [reduce tbl init f] computes
[(f kN dN ... (f k1 d1 init)...)],
Expand All @@ -133,11 +131,10 @@ val reduce: ('key, 'value, 'id ) t -> 'c -> ('c -> 'key -> 'value -> 'c) -> 'c
*)


val keepMapInPlaceU: ('key, 'value, 'id ) t -> ('key -> 'value -> 'value option [@bs]) -> unit
val keepMapInPlace: ('key, 'value, 'id ) t -> ('key -> 'value -> 'value option ) -> unit


val size: _ t -> int
val size: _ t -> int
(** [size tbl] returns the number of bindings in [tbl].
It takes constant time. *)

Expand All @@ -146,14 +143,23 @@ val size: _ t -> int



val toArray: ('key, 'value, 'id ) t -> ('key * 'value) array
val keysToArray: ('key, _, _) t -> 'key array
val valuesToArray: (_,'value,_) t -> 'value array
val fromArray: ('key * 'value) array -> id:('key,'id) id -> ('key, 'value, 'id ) t
val toArray: ('key, 'value, 'id ) t -> ('key * 'value) array
val keysToArray: ('key, _, _) t -> 'key array
val valuesToArray: (_,'value,_) t -> 'value array
val fromArray: ('key * 'value) array -> id:('key,'id) id -> ('key, 'value, 'id ) t
val mergeMany: ('key, 'value, 'id ) t -> ('key * 'value) array -> unit
val getBucketHistogram: _ t -> int array
val logStats: _ t -> unit

val ofArray: ('key * 'value) array -> id:('key,'id) id -> ('key, 'value, 'id ) t
val ofArray: ('key * 'value) array -> id:('key,'id) id -> ('key, 'value, 'id ) t
[@@ocaml.deprecated "Use fromArray instead"]


(** {1 Uncurried version} *)


val forEachU: ('key, 'value, 'id ) t -> ('key -> 'value -> unit [@bs]) -> unit

val reduceU: ('key, 'value, 'id ) t -> 'c -> ('c -> 'key -> 'value -> 'c [@bs]) -> 'c

val keepMapInPlaceU: ('key, 'value, 'id ) t -> ('key -> 'value -> 'value option [@bs]) -> unit
24 changes: 14 additions & 10 deletions jscomp/others/belt_HashSet.mli
Expand Up @@ -30,7 +30,7 @@
For example:
{[
type t = int
type t = int
module I0 =
(val Belt.Id.hashableU
~hash:(fun[\@bs] (a : t) -> a & 0xff_ff)
Expand Down Expand Up @@ -74,7 +74,7 @@
module Int = Belt_HashSetInt

(** Specalized when key type is [string], more efficient
than the gerneic type *)
than the gerneic type *)
module String = Belt_HashSetString

(* TODO: add a poly module
Expand All @@ -83,8 +83,8 @@ module String = Belt_HashSetString
- generic equal handles JS data structure
- eq/hash consistent
*)
type ('a, 'id) t

type ('a, 'id) t

(** The type of hash tables from type ['a] to type ['b]. *)

Expand All @@ -102,27 +102,31 @@ val has: ('a, 'id) t -> 'a -> bool

val remove: ('a, 'id) t -> 'a -> unit

val forEachU: ('a, 'id) t -> ('a -> unit [@bs]) -> unit
val forEach: ('a, 'id) t -> ('a -> unit) -> unit
(** Order unspecified. *)

val reduceU: ('a, 'id) t -> 'c -> ('c -> 'a -> 'c [@bs]) -> 'c
val reduce: ('a, 'id) t -> 'c -> ('c -> 'a -> 'c) -> 'c
(** Order unspecified. *)

val size: ('a, 'id) t -> int
val size: ('a, 'id) t -> int

val logStats: _ t -> unit

val toArray: ('a,'id) t -> 'a array
val toArray: ('a,'id) t -> 'a array

val ofArray: 'a array -> id:('a,'id) id -> ('a,'id) t
val ofArray: 'a array -> id:('a,'id) id -> ('a,'id) t
[@@ocaml.deprecated "Use fromArray instead"]

val fromArray: 'a array -> id:('a,'id) id -> ('a,'id) t
val fromArray: 'a array -> id:('a,'id) id -> ('a,'id) t

val mergeMany: ('a,'id) t -> 'a array -> unit

val getBucketHistogram: _ t -> int array


(** {1 Uncurried version} *)


val forEachU: ('a, 'id) t -> ('a -> unit [@bs]) -> unit

val reduceU: ('a, 'id) t -> 'c -> ('c -> 'a -> 'c [@bs]) -> 'c
35 changes: 20 additions & 15 deletions jscomp/others/belt_Id.mli
Expand Up @@ -74,13 +74,6 @@ type ('key, 'id) comparable =
mismatch if they use different comparison function
*)

module MakeComparableU :
functor (M : sig
type t
val cmp : t -> t -> int [@bs]
end) ->
Comparable with type t = M.t

module MakeComparable :
functor (M : sig
type t
Expand Down Expand Up @@ -118,14 +111,6 @@ type ('key, 'id) hashable =
mismatch if they use different comparison function
*)

module MakeHashableU :
functor (M : sig
type t
val hash : t -> int [@bs]
val eq : t -> t -> bool [@bs]
end) ->
Hashable with type t = M.t

module MakeHashable :
functor (M : sig
type t
Expand Down Expand Up @@ -153,3 +138,23 @@ external getHashInternal : ('a,'id) hash -> ('a -> int [@bs]) = "%identity"
external getEqInternal : ('a, 'id) eq -> ('a -> 'a -> bool [@bs]) = "%identity"
external getCmpInternal : ('a,'id) cmp -> ('a -> 'a -> int [@bs]) = "%identity"
(**/**)


(** {1 Uncurried version} *)


module MakeComparableU :
functor (M : sig
type t
val cmp : t -> t -> int [@bs]
end) ->
Comparable with type t = M.t


module MakeHashableU :
functor (M : sig
type t
val hash : t -> int [@bs]
val eq : t -> t -> bool [@bs]
end) ->
Hashable with type t = M.t

0 comments on commit ce9ac60

Please sign in to comment.