Skip to content

Commit

Permalink
Merge 9276c34 into ba5b84e
Browse files Browse the repository at this point in the history
  • Loading branch information
bobzhang committed Jan 27, 2018
2 parents ba5b84e + 9276c34 commit 84780bf
Show file tree
Hide file tree
Showing 124 changed files with 2,463 additions and 2,451 deletions.
11 changes: 7 additions & 4 deletions jscomp/others/.depend
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bs_Hash.cmj : bs_Hash.cmi
bs_Queue.cmj : bs_Array.cmj bs_Queue.cmi
bs_List.cmj : bs_Array.cmj bs_List.cmi
bs_Sort.cmj : bs_Array.cmj bs_Sort.cmi
bs_Range.cmj :
bs_Range.cmj : bs_Range.cmi
bs_internalBucketsType.cmj : bs_Array.cmj bs_internalBucketsType.cmi
bs_internalSetBuckets.cmj : bs_internalBucketsType.cmj bs_Array.cmj bs.cmj \
bs_internalSetBuckets.cmi
Expand All @@ -46,8 +46,9 @@ bs_HashSetInt.cmj : bs_internalSetBuckets.cmj bs_internalBucketsType.cmj \
bs_Bag.cmj :
bs_BagM.cmj :
bs_Cmp.cmj : bs_Cmp.cmi
bs_Map.cmj : bs_internalAVLtree.cmj bs_Cmp.cmj bs_Bag.cmj bs_Array.cmj \
bs_Map.cmi
bs_SortedMapDict.cmj : bs_internalAVLtree.cmj bs_Cmp.cmj bs_Array.cmj \
bs_SortedMapDict.cmi
bs_Map.cmj : bs_SortedMapDict.cmj bs_Cmp.cmj bs_Array.cmj bs_Map.cmi
bs_internalMapInt.cmj : bs_internalAVLtree.cmj bs_Sort.cmj bs_Array.cmj
bs_internalMapString.cmj : bs_internalAVLtree.cmj bs_Sort.cmj bs_Array.cmj
bs_MapString.cmj : bs_internalMapString.cmj bs_internalAVLtree.cmj \
Expand Down Expand Up @@ -108,6 +109,7 @@ bs_Hash.cmi :
bs_Queue.cmi :
bs_List.cmi :
bs_Sort.cmi :
bs_Range.cmi :
bs_internalBucketsType.cmi :
bs_internalSetBuckets.cmi : bs_internalBucketsType.cmi
bs_internalBuckets.cmi : bs_internalBucketsType.cmi
Expand All @@ -117,7 +119,8 @@ bs_HashSet.cmi : bs_Hash.cmi
bs_HashSetString.cmi :
bs_HashSetInt.cmi :
bs_Cmp.cmi :
bs_Map.cmi : bs_Cmp.cmi
bs_SortedMapDict.cmi : bs_Cmp.cmi
bs_Map.cmi : bs_SortedMapDict.cmi bs_Cmp.cmi
bs_MapString.cmi :
bs_MapInt.cmi :
bs_MapStringM.cmi :
Expand Down
1 change: 1 addition & 0 deletions jscomp/others/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ SOURCE_LIST= node_path node_fs node_process dict node_module js_array js_string
bs_Bag\
bs_BagM\
bs_Cmp\
bs_SortedMapDict\
bs_Map\
bs_internalMapInt\
bs_internalMapString\
Expand Down
1 change: 1 addition & 0 deletions jscomp/others/bs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ module SortInt = Bs_SortInt
module SortString = Bs_SortString
module Stack = Bs_Stack
module Range = Bs_Range
module SortedMapDict = Bs_SortedMapDict
module Map = Bs_Map
module MapM = Bs_MapM
module Set = Bs_Set
Expand Down
52 changes: 16 additions & 36 deletions jscomp/others/bs_HashMap.ml
Original file line number Diff line number Diff line change
Expand Up @@ -174,36 +174,24 @@ let has0 ~hash ~eq h key =
memInBucket ~eq key bucket


let create0 = C.create0
let clear0 = C.clear0
let size0 = C.size
let forEach0 = N.forEach0
let reduce0 = N.reduce0
let logStats0 = N.logStats0
let filterMapDone0 = N.filterMapInplace0
let toArray0 = N.toArray0


let create initialize_size ~dict =
B.bag ~data:(create0 initialize_size) ~dict
let clear h = clear0 (B.data h)


let make initialize_size ~dict =
B.bag ~data:(C.create0 initialize_size) ~dict
let clear h = C.clear0 (B.data h)
let size h = C.size (B.data h)
let forEach h f = N.forEach0 (B.data h) f
let reduce h init f = N.reduce0 (B.data h) init f
let logStats h = logStats0 (B.data h)
let logStats h = N.logStats0 (B.data h)

let setDone (type a) (type id) (h : (a,_,id) t) (key:a) info =
let set (type a) (type id) (h : (a,_,id) t) (key:a) info =
let module M = (val B.dict h) in
setDone0 ~hash:M.hash ~eq:M.eq (B.data h) key info

let set h key info = setDone h key info; h

let removeDone (type a) (type id) (h : (a,_,id) t) (key : a) =
let remove (type a) (type id) (h : (a,_,id) t) (key : a) =
let module M = (val B.dict h) in
remove0 ~hash:M.hash ~eq:M.eq (B.data h) key

let remove h key = removeDone h key; h

let get (type a) (type id) (h : (a, _, id) t) (key : a) =
let module M = (val B.dict h) in
get0 ~hash:M.hash ~eq:M.eq (B.data h) key
Expand All @@ -212,15 +200,14 @@ let has (type a) (type id) (h : (a,_,id) t) (key : a) =
let module M = (val B.dict h) in
has0 ~hash:M.hash ~eq:M.eq (B.data h) key

let filterMapDone h f = filterMapDone0 (B.data h) f
let keepMapInPlace h f = N.filterMapInplace0 (B.data h) f

let filterMap h f = filterMapDone h f; h

let toArray h = toArray0 (B.data h)
let toArray h = N.toArray0 (B.data h)

let ofArray0 arr ~hash ~eq =
let len = A.length arr in
let v = create0 len in
let v = C.create0 len in
for i = 0 to len - 1 do
let key,value = (A.getUnsafe arr i) in
setDone0 ~eq ~hash v key value
Expand All @@ -234,28 +221,21 @@ let mergeArrayDone0 h arr ~hash ~eq =
let key,value = (A.getUnsafe arr i) in
setDone0 h ~eq ~hash key value
done

let mergeArray0 h arr ~hash ~eq = mergeArrayDone0 h arr ~hash ~eq; h


let ofArray (type a) (type id) arr ~dict:(dict:(a,id) Bs_Hash.t) =
let module M = (val dict) in
B.bag ~dict ~data:M.(ofArray0 ~eq ~hash arr)

let mergeArrayDone (type a) (type id) (h : (a,_,id) t) arr =
let mergeMany (type a) (type id) (h : (a,_,id) t) arr =
let module M = (val B.dict h) in
mergeArrayDone0 ~hash:M.hash ~eq:M.eq (B.data h) arr

let mergeArray h arr =
mergeArrayDone h arr;
h

let copy h = B.bag ~dict:(B.dict h) ~data:(N.copy (B.data h))

let keysToArray0 = N.keys0
let keysToArray h = N.keys0 (B.data h)
let valuesToArray0 = N.values0

let valuesToArray h = N.values0 (B.data h)
let getBucketHistogram h = N.getBucketHistogram (B.data h)
let getData = B.data
let getDict = B.dict
let packDictData = B.bag

let isEmpty h = C.size (B.data h) = 0
130 changes: 27 additions & 103 deletions jscomp/others/bs_HashMap.mli
Original file line number Diff line number Diff line change
Expand Up @@ -25,55 +25,41 @@



type ('a,'b,'id) t

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

val create: int -> dict:('a,'id) Bs_Hash.t -> ('a,'b,'id) t
val make: int -> dict:('key, 'id) Bs_Hash.t -> ('key,'value,'id) t
(*TODO: allow randomization for security *)

val clear: ('a, 'b, 'id) t -> unit
(** Empty a hash table. Use [reset] instead of [clear] to shrink the
size of the bucket table to its initial size. *)

val clear: ('key, 'value, 'id ) t -> unit
(** Empty a hash table. *)

val isEmpty: _ t -> bool

val setDone: ('a, 'b, 'id) t -> 'a -> 'b -> unit
(** [setDone tbl k v] if [k] does not exist,
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 set: ('a, 'b, 'id) t -> 'a -> 'b -> ('a, 'b, 'id) t
(** [set tbl k v]
*)
val copy: ('a, 'b, 'id) t -> ('a, 'b, 'id) t
val copy: ('key, 'value, 'id ) t -> ('key, 'value, 'id ) t

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


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

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

val forEach: ('a, 'b, 'id) t -> ('a -> 'b -> unit [@bs]) -> unit
val forEach: ('key, 'value, 'id ) t -> ('key -> 'value -> unit [@bs]) -> 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].
If the hash table was created in non-randomized mode, the order
in which the bindings are enumerated is reproducible between
successive runs of the program. *)
*)


val reduce: ('a, 'b, 'id) t -> 'c -> ('c -> 'a -> 'b -> 'c [@bs]) -> 'c
val reduce: ('key, 'value, 'id ) t -> 'c -> ('c -> 'key -> 'value -> 'c [@bs]) -> 'c
(** [reduce tbl init f] computes
[(f kN dN ... (f k1 d1 init)...)],
where [k1 ... kN] are the keys of all bindings in [tbl],
Expand All @@ -84,19 +70,13 @@ val reduce: ('a, 'b, 'id) t -> 'c -> ('c -> 'a -> 'b -> 'c [@bs]) -> 'c
However, if the table contains several bindings for the same key,
they are passed to [f] in reverse order of introduction, that is,
the most recent binding is passed first.
If the hash table was created in non-randomized mode, the order
in which the bindings are enumerated is reproducible between
successive runs of the program, and even between minor versions
of OCaml. For randomized hash tables, the order of enumeration
is entirely random. *)
*)


val filterMapDone: ('a, 'b, 'id) t -> ('a -> 'b -> 'b option [@bs]) -> unit
val filterMap: ('a, 'b, 'id) t -> ('a -> 'b -> 'b option [@bs]) -> ('a, 'b, 'id) t
val keepMapInPlace: ('key, 'value, 'id ) t -> ('key -> 'value -> 'value option [@bs]) -> unit


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

Expand All @@ -111,79 +91,23 @@ val logStats: _ t -> unit



val toArray: ('a, 'b, 'id) t -> ('a * 'b) array
val toArray: ('key, 'value, 'id ) t -> ('key * 'value) array




val ofArray:
('a * 'b) array ->
dict:('a,'id) Bs_Hash.t ->
('a, 'b, 'id) t
val mergeArrayDone: ('a, 'b, 'id) t -> ('a * 'b) array -> unit
val mergeArray: ('a, 'b, 'id) t -> ('a * 'b) array -> ('a, 'b, 'id) t
val ofArray: ('key * 'value) array -> dict:('key,'id) Bs_Hash.t -> ('key, 'value, 'id ) t

val mergeMany: ('key, 'value, 'id ) t -> ('key * 'value) array -> unit

val keysToArray:
('a,'b,'id) t -> 'a array
('key, _, _) t -> 'key array
val valuesToArray:
('a,'b,'id) t -> 'b array
(_,'value,_) t -> 'value array

val getBucketHistogram: _ t -> int array
(****************************************************************************)

type ('a, 'b, 'id) t0
val getData: ('k,'v,'id) t -> ('k,'v,'id) t0
val getDict: ('k,'v,'id) t -> ('k,'id) Bs_Hash.t
val packDictData: dict:('k, 'id) Bs_Hash.t -> data:('k, 'v, 'id) t0 -> ('k, 'v, 'id) t
val create0: int -> ('a, 'b, 'id) t0
val clear0: ('a, 'b, 'id) t0 -> unit
val setDone0 :
hash:('a,'id) Bs_Hash.hash ->
eq:('a,'id) Bs_Hash.eq ->
('a,'b,'id) t0 -> 'a ->
'b -> unit
val get0:
hash:('a,'id) Bs_Hash.hash ->
eq:('a,'id) Bs_Hash.eq ->
('a, 'b, 'id) t0 ->
'a ->
'b option

val has0:
hash:('a,'id) Bs_Hash.hash ->
eq:('a,'id) Bs_Hash.eq ->
('a, 'b, 'id) t0 ->
'a ->
bool

val remove0:
hash:('a,'id) Bs_Hash.hash ->
eq:('a,'id) Bs_Hash.eq ->
('a, 'b, 'id) t0 ->
'a ->
unit

val forEach0: ('a, 'b, 'id) t0 -> ('a -> 'b -> unit [@bs]) -> unit
val reduce0: ('a, 'b, 'id) t0 -> 'c -> ('c -> 'a -> 'b -> 'c [@bs]) -> 'c
val filterMapDone0: ('a, 'b, 'id) t0 -> ('a -> 'b -> 'b option [@bs]) -> unit
val size0: ('a, 'b, 'id) t0 -> int
val logStats0: ('a, 'b, 'id) t0 -> unit
val toArray0: ('a, 'b, 'id) t0 -> ('a * 'b) array
val ofArray0:
('a * 'b) array ->
hash:('a,'id) Bs_Hash.hash ->
eq:('a,'id) Bs_Hash.eq ->
('a, 'b, 'id) t0
val mergeArray0:
('a, 'b, 'id) t0 ->
('a * 'b) array ->
hash:('a,'id) Bs_Hash.hash ->
eq:('a,'id) Bs_Hash.eq ->
('a, 'b, 'id) t0

val keysToArray0:
('a,'b,'id) t0 -> 'a array
val valuesToArray0:
('a,'b,'id) t0 -> 'b array





Loading

0 comments on commit 84780bf

Please sign in to comment.