Skip to content

Commit

Permalink
Merge pull request #2468 from BuckleScript/clean_up_list_interface_pe…
Browse files Browse the repository at this point in the history
…r_feedback

clean up hash interface
  • Loading branch information
bobzhang committed Jan 29, 2018
2 parents ba5b84e + 0050d00 commit b7d0dec
Show file tree
Hide file tree
Showing 176 changed files with 6,535 additions and 6,494 deletions.
95 changes: 53 additions & 42 deletions jscomp/others/.depend
Original file line number Diff line number Diff line change
Expand Up @@ -17,66 +17,74 @@ js_console.cmj :
js_result.cmj : js_result.cmi
js_mapperRt.cmj : js_mapperRt.cmi
bs_Array.cmj : js_math.cmj bs_Array.cmi
bs_internalAVLset.cmj : bs_Sort.cmj bs_Cmp.cmj bs_Array.cmj \
bs_internalAVLset.cmj : bs_SortArray.cmj bs_Cmp.cmj bs_Array.cmj \
bs_internalAVLset.cmi
bs_internalAVLtree.cmj : bs_Sort.cmj bs_Cmp.cmj bs_Array.cmj \
bs_internalAVLtree.cmj : bs_SortArray.cmj bs_Cmp.cmj bs_Array.cmj \
bs_internalAVLtree.cmi
bs_SetIntM.cmj : bs_internalSetInt.cmj bs_internalAVLset.cmj bs_SortInt.cmj \
bs_Array.cmj bs_SetIntM.cmi
bs_SetIntM.cmj : bs_internalSetInt.cmj bs_internalAVLset.cmj \
bs_SortArrayInt.cmj bs_Array.cmj bs_SetIntM.cmi
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_SortArray.cmj : bs_SortArrayString.cmj bs_SortArrayInt.cmj bs_Array.cmj \
bs_SortArray.cmi
bs_SortArrayInt.cmj : bs_Array.cmj bs_SortArrayInt.cmi
bs_SortArrayString.cmj : bs_Array.cmj bs_SortArrayString.cmi
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
bs_internalBuckets.cmj : bs_internalBucketsType.cmj bs_Array.cmj \
bs_internalBuckets.cmi
bs_HashMap.cmj : bs_internalBucketsType.cmj bs_internalBuckets.cmj \
bs_Hash.cmj bs_Bag.cmj bs_Array.cmj bs_HashMap.cmi
bs_HashMapString.cmj bs_HashMapInt.cmj bs_Hash.cmj bs_Array.cmj \
bs_HashMap.cmi
bs_HashMultiMap.cmj : bs_internalBucketsType.cmj bs_internalBuckets.cmj \
bs_Hash.cmj bs_Bag.cmj bs_Array.cmj bs_HashMultiMap.cmi
bs_Hash.cmj bs_Array.cmj bs_HashMultiMap.cmi
bs_HashSet.cmj : bs_internalSetBuckets.cmj bs_internalBucketsType.cmj \
bs_Hash.cmj bs_Bag.cmj bs_Array.cmj bs.cmj bs_HashSet.cmi
bs_HashSetString.cmj bs_HashSetInt.cmj bs_Hash.cmj bs_Array.cmj bs.cmj \
bs_HashSet.cmi
bs_HashSetString.cmj : bs_internalSetBuckets.cmj bs_internalBucketsType.cmj \
bs_Array.cmj bs.cmj bs_HashSetString.cmi
bs_HashSetInt.cmj : bs_internalSetBuckets.cmj bs_internalBucketsType.cmj \
bs_Array.cmj bs.cmj bs_HashSetInt.cmi
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_internalMapInt.cmj : bs_internalAVLtree.cmj bs_Sort.cmj bs_Array.cmj
bs_internalMapString.cmj : bs_internalAVLtree.cmj bs_Sort.cmj bs_Array.cmj
bs_SortedMapDict.cmj : bs_internalAVLtree.cmj bs_Cmp.cmj bs_Array.cmj \
bs_SortedMapDict.cmi
bs_SortedSetDict.cmj : bs_internalAVLset.cmj bs_Cmp.cmj bs_Array.cmj \
bs_SortedSetDict.cmi
bs_Map.cmj : bs_SortedMapDict.cmj bs_MapString.cmj bs_MapInt.cmj bs_Cmp.cmj \
bs_Array.cmj bs_Map.cmi
bs_internalMapInt.cmj : bs_internalAVLtree.cmj bs_SortArray.cmj bs_Array.cmj
bs_internalMapString.cmj : bs_internalAVLtree.cmj bs_SortArray.cmj \
bs_Array.cmj
bs_MapString.cmj : bs_internalMapString.cmj bs_internalAVLtree.cmj \
bs_Sort.cmj bs_Array.cmj bs_MapString.cmi
bs_MapInt.cmj : bs_internalMapInt.cmj bs_internalAVLtree.cmj bs_Sort.cmj \
bs_Array.cmj bs_MapInt.cmi
bs_Array.cmj bs_MapString.cmi
bs_MapInt.cmj : bs_internalMapInt.cmj bs_internalAVLtree.cmj bs_Array.cmj \
bs_MapInt.cmi
bs_MapStringM.cmj : bs_internalMapString.cmj bs_internalAVLtree.cmj \
bs_SortString.cmj bs_Array.cmj bs_MapStringM.cmi
bs_MapIntM.cmj : bs_internalMapInt.cmj bs_internalAVLtree.cmj bs_SortInt.cmj \
bs_Array.cmj bs_MapIntM.cmi
bs_Set.cmj : bs_internalAVLset.cmj bs_Cmp.cmj bs_Bag.cmj bs_Array.cmj \
bs_Set.cmi
bs_SetM.cmj : bs_internalAVLset.cmj bs_Sort.cmj bs_Cmp.cmj bs_BagM.cmj \
bs_Array.cmj bs_SetM.cmi
bs_MapM.cmj : bs_internalAVLtree.cmj bs_Sort.cmj bs_Cmp.cmj bs_BagM.cmj \
bs_Array.cmj bs_MapM.cmi
bs_internalSetInt.cmj : bs_internalAVLset.cmj bs_SortInt.cmj bs_Array.cmj
bs_internalSetString.cmj : bs_internalAVLset.cmj bs_SortString.cmj \
bs_Array.cmj bs_MapStringM.cmi
bs_MapIntM.cmj : bs_internalMapInt.cmj bs_internalAVLtree.cmj bs_Array.cmj \
bs_MapIntM.cmi
bs_Set.cmj : bs_SortedSetDict.cmj bs_Cmp.cmj bs_Array.cmj bs_Set.cmi
bs_SetM.cmj : bs_internalAVLset.cmj bs_SortArray.cmj bs_SetStringM.cmj \
bs_SetIntM.cmj bs_Cmp.cmj bs_Array.cmj bs_SetM.cmi
bs_MapM.cmj : bs_internalAVLtree.cmj bs_MapStringM.cmj bs_MapIntM.cmj \
bs_Cmp.cmj bs_Array.cmj bs_MapM.cmi
bs_internalSetInt.cmj : bs_internalAVLset.cmj bs_SortArrayInt.cmj \
bs_Array.cmj
bs_internalSetString.cmj : bs_internalAVLset.cmj bs_SortArrayString.cmj \
bs_Array.cmj
bs_SetInt.cmj : bs_internalSetInt.cmj bs_internalAVLset.cmj bs_Array.cmj \
bs_SetInt.cmi
bs_SetIntM.cmj : bs_internalSetInt.cmj bs_internalAVLset.cmj bs_SortInt.cmj \
bs_Array.cmj bs_SetIntM.cmi
bs_SetIntM.cmj : bs_internalSetInt.cmj bs_internalAVLset.cmj \
bs_SortArrayInt.cmj bs_Array.cmj bs_SetIntM.cmi
bs_SetString.cmj : bs_internalSetString.cmj bs_internalAVLset.cmj \
bs_Array.cmj bs_SetString.cmi
bs_SetStringM.cmj : bs_internalSetString.cmj bs_internalAVLset.cmj \
bs_SortString.cmj bs_Array.cmj bs_SetStringM.cmi
bs_SortInt.cmj : bs_Array.cmj bs_SortInt.cmi
bs_SortString.cmj : bs_Array.cmj bs_SortString.cmi
bs_SortArrayString.cmj bs_Array.cmj bs_SetStringM.cmi
bs_Stack.cmj : bs_Stack.cmi
node_child_process.cmj : node.cmj
js_boolean.cmj : js_boolean.cmi
Expand Down Expand Up @@ -107,30 +115,33 @@ bs_SetIntM.cmi :
bs_Hash.cmi :
bs_Queue.cmi :
bs_List.cmi :
bs_Sort.cmi :
bs_SortArray.cmi : bs_SortArrayString.cmi bs_SortArrayInt.cmi
bs_SortArrayInt.cmi :
bs_SortArrayString.cmi :
bs_Range.cmi :
bs_internalBucketsType.cmi :
bs_internalSetBuckets.cmi : bs_internalBucketsType.cmi
bs_internalBuckets.cmi : bs_internalBucketsType.cmi
bs_HashMap.cmi : bs_Hash.cmi
bs_HashMultiMap.cmi : bs_Hash.cmi bs_Bag.cmj
bs_HashSet.cmi : bs_Hash.cmi
bs_HashMap.cmi : bs_HashMapString.cmi bs_HashMapInt.cmi bs_Hash.cmi
bs_HashMultiMap.cmi : bs_Hash.cmi
bs_HashSet.cmi : bs_HashSetString.cmi bs_HashSetInt.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_SortedSetDict.cmi : bs_Cmp.cmi
bs_Map.cmi : bs_SortedMapDict.cmi bs_MapString.cmi bs_MapInt.cmi bs_Cmp.cmi
bs_MapString.cmi :
bs_MapInt.cmi :
bs_MapStringM.cmi :
bs_MapIntM.cmi :
bs_Set.cmi : bs_Cmp.cmi
bs_SetM.cmi : bs_Cmp.cmi
bs_MapM.cmi : bs_Cmp.cmi
bs_Set.cmi : bs_SortedSetDict.cmi bs_Cmp.cmi
bs_SetM.cmi : bs_SetStringM.cmi bs_SetIntM.cmi bs_Cmp.cmi
bs_MapM.cmi : bs_MapStringM.cmi bs_MapIntM.cmi bs_Cmp.cmi
bs_SetInt.cmi :
bs_SetIntM.cmi :
bs_SetString.cmi :
bs_SetStringM.cmi :
bs_SortInt.cmi :
bs_SortString.cmi :
bs_Stack.cmi :
js_boolean.cmi :
js_dict.cmi :
Expand Down
18 changes: 10 additions & 8 deletions jscomp/others/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ SOURCE_LIST= node_path node_fs node_process dict node_module js_array js_string
bs_Hash\
bs_Queue\
bs_List\
bs_Sort\
bs_SortArray\
bs_SortArrayInt\
bs_SortArrayString\
bs_Range\
bs_internalBucketsType\
bs_internalSetBuckets\
Expand All @@ -31,6 +33,8 @@ SOURCE_LIST= node_path node_fs node_process dict node_module js_array js_string
bs_Bag\
bs_BagM\
bs_Cmp\
bs_SortedMapDict\
bs_SortedSetDict\
bs_Map\
bs_internalMapInt\
bs_internalMapString\
Expand All @@ -48,8 +52,6 @@ SOURCE_LIST= node_path node_fs node_process dict node_module js_array js_string
bs_SetIntM\
bs_SetString\
bs_SetStringM\
bs_SortInt\
bs_SortString\
bs_Stack\
node_child_process \
js_boolean js_math\
Expand Down Expand Up @@ -91,7 +93,7 @@ clean::
bs_internalSetInt.ml bs_internalSetString.ml \
bs_SetInt.ml bs_SetInt.mli bs_SetString.ml bs_SetString.mli \
bs_SetIntM.ml bs_SetIntM.mli bs_SetStringM.ml bs_SetStringM.mli\
bs_SortInt.ml bs_SortInt.mli bs_SortString.ml bs_SortString.mli\
bs_SortArrayInt.ml bs_SortArrayInt.mli bs_SortArrayString.ml bs_SortArrayString.mli\
bs_internalMapInt.ml bs_internalMapInt.mli \
bs_internalMapIntM.ml bs_internalMapIntM.mli \
bs_internalMapString.ml bs_internalMapString.mli\
Expand Down Expand Up @@ -160,13 +162,13 @@ bs_SetIntM.mli: setm.cppo.mli
bs_SetStringM.mli: setm.cppo.mli
cppo -D TYPE_STRING $^ > $@

bs_SortInt.ml : sort.cppo.ml
bs_SortArrayInt.ml : sort.cppo.ml
cppo -D TYPE_INT $^ >$@
bs_SortString.ml : sort.cppo.ml
bs_SortArrayString.ml : sort.cppo.ml
cppo -D TYPE_STRING $^ >$@
bs_SortInt.mli : sort.cppo.mli
bs_SortArrayInt.mli : sort.cppo.mli
cppo -D TYPE_INT $^ > $@
bs_SortString.mli : sort.cppo.mli
bs_SortArrayString.mli : sort.cppo.mli
cppo -D TYPE_STRING $^ > $@
endif

Expand Down
86 changes: 70 additions & 16 deletions jscomp/others/bs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,80 @@ module Cmp = Bs_Cmp
module Hash = Bs_Hash
module Array = Bs_Array
module Queue = Bs_Queue
module HashMap = Bs_HashMap
module HashSet = Bs_HashSet
module HashSetInt = Bs_HashSetInt
module HashSetString = Bs_HashSetString
module HashMapString = Bs_HashMapString
module HashMapInt = Bs_HashMapInt
module Sort = Bs_Sort
module SortInt = Bs_SortInt
module SortString = Bs_SortString
module List = Bs_List
module Stack = Bs_Stack
module Range = Bs_Range
module Map = Bs_Map
module MapM = Bs_MapM

(** Immutable sorted set *)
module Set = Bs_Set
module SetM = Bs_SetM
module MapInt = Bs_MapInt
module MapString = Bs_MapString

(** The implementation detail for {!Bs.Set}, also slightly more efficient *)
module SetDict = Bs_SortedSetDict

(** can also be accessed via {!Bs.Set.Int}*)
module SetInt = Bs_SetInt
module SetIntM = Bs_SetIntM

(** can also be accessed via {!Bs.Set.String}*)
module SetString = Bs_SetString
module List = Bs_List


module MutableSet = Bs_SetM

(** can also be accessed via {!Bs.MutableSet.Int}*)
module MutableSetInt = Bs_SetIntM

(** can also be accessed via {!Bs.MutableSet.String}*)
module MutableSetString = Bs_SetIntM


module UnorderedMutableSet = Bs_HashSet

(** can also be accessed via {!Bs.UnordedMutableSet.Int}*)
module UnorderedMutableSetInt = Bs_HashSetInt

(** can also be accessed via {!Bs.UnordedMutableSet.String}*)
module UnorderedMutableSetString = Bs_HashSetString


module Map = Bs_Map

(** The implementaion detail for {!Bs.Map}, also slightly more efficient*)
module MapDict = Bs_SortedMapDict

(** can also be accessed via {!Bs.Map.Int}*)
module MapInt = Bs_MapInt

(** can also be accessed via {!Bs.Map.String}*)
module MapString = Bs_MapString


module MutableMap = Bs_MapM

(** can also be accessed via {!Bs.MutableMap.Int}*)
module MutableMapInt = Bs_MapIntM

(** can also be accessed via {!Bs.MutableMap.String}*)
module MutableMapString = Bs_MapStringM


module UnorderedMutableMap = Bs_HashMap

(** can also be accessed via {!Bs.UnorderedMutableMap.Int}*)
module UnorderedMutableMapInt = Bs_HashMapInt

(** can also be accessed via {!Bs.UnorderedMutableMap.String}*)
module UnorderedMutableMapString = Bs_HashMapString


module SortArray = Bs_SortArray

(** can also be accessed via {!Bs.SortArray.Int}*)
module SortArrayInt = Bs_SortArrayInt

(** can also be accessed via {!Bs.SortArray.String}*)
module SortArrayString = Bs_SortArrayString




(* module HashMultiMap = Bs_HashMultiMap *)
6 changes: 3 additions & 3 deletions jscomp/others/bs_Array.ml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ let zip xs ys =
done ;
s

let map2 xs ys f =
let zipBy xs ys f =
let lenx, leny = length xs, length ys in
let len = Pervasives.min lenx leny in
let s = makeUninitializedUnsafe len in
Expand Down Expand Up @@ -331,7 +331,7 @@ let every2 a b p =
else
everyAux2 a b 0 p lena

let equalTo = every2
let eq = every2

let rec everyCmpAux2 arr1 arr2 i b len =
if i = len then 0
Expand All @@ -341,7 +341,7 @@ let rec everyCmpAux2 arr1 arr2 i b len =
everyCmpAux2 arr1 arr2 (i + 1) b len
else c

let compareTo a b p =
let cmp a b p =
let lena = length a in
let lenb = length b in
if lena > lenb then 1
Expand Down
6 changes: 3 additions & 3 deletions jscomp/others/bs_Array.mli
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ val forEach: 'a array -> ('a -> unit [@bs]) -> unit

val map: 'a array -> ('a -> 'b [@bs]) -> 'b array

val map2: 'a array -> 'b array -> ('a -> 'b -> 'c [@bs]) -> 'c array
val zipBy: 'a array -> 'b array -> ('a -> 'b -> 'c [@bs]) -> 'c array

val keepBy: 'a array -> ('a -> bool [@bs]) -> 'a array

Expand All @@ -121,7 +121,7 @@ val every: 'a array -> ('a -> bool [@bs]) -> bool
(** [every2 a b] return false when [length a <> length b] *)
val every2: 'a array -> 'b array -> ('a -> 'b -> bool [@bs]) -> bool

val compareTo: 'a array -> 'a array -> ('a -> 'a -> int [@bs]) -> int
val equalTo: 'a array -> 'a array -> ('a -> 'a -> bool [@bs]) -> bool
val cmp: 'a array -> 'a array -> ('a -> 'a -> int [@bs]) -> int
val eq: 'a array -> 'a array -> ('a -> 'a -> bool [@bs]) -> bool

external truncateToLengthUnsafe: 'a array -> int -> unit = "length" [@@bs.set]
10 changes: 5 additions & 5 deletions jscomp/others/bs_Cmp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
type 'a compare = ('a -> 'a -> int [@bs])
type ('a,'id) cmp = 'a compare

external getCmp : ('a,'id) cmp -> 'a compare = "%identity"
external getCmpIntenral : ('a,'id) cmp -> 'a compare = "%identity"

module type S = sig
module type T = sig
type id
type t
val cmp : (t,id) cmp
end
type ('key, 'id) t = (module S with type t = 'key and type id = 'id)
type ('key, 'id) t = (module T with type t = 'key and type id = 'id)

module Make (M : sig
type t
Expand All @@ -47,12 +47,12 @@ end

let make
(type key)
(cmp : key -> key -> int [@bs])
~(cmp : key -> key -> int [@bs])
=
let module M = struct
type t = key
let cmp = cmp
end in
let module N = Make(M) in
(module N : S with type t = key)
(module N : T with type t = key)

Loading

0 comments on commit b7d0dec

Please sign in to comment.