Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 23 additions & 25 deletions jscomp/others/.depend
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ 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_SortArray.cmj bs_Dict.cmj bs_Array.cmj \
bs_internalAVLset.cmj : bs_SortArray.cmj bs_Id.cmj bs_Array.cmj \
bs_internalAVLset.cmi
bs_internalAVLtree.cmj : bs_SortArray.cmj bs_Dict.cmj bs_Array.cmj \
bs_internalAVLtree.cmj : bs_SortArray.cmj bs_Id.cmj bs_Array.cmj \
bs_internalAVLtree.cmi
bs_List.cmj : bs_Array.cmj bs_List.cmi
bs_SortArray.cmj : bs_SortArrayString.cmj bs_SortArrayInt.cmj bs_Array.cmj \
Expand All @@ -32,22 +32,20 @@ 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_HashMapString.cmj bs_HashMapInt.cmj bs_Dict.cmj bs_Array.cmj \
bs_HashMap.cmi
bs_HashMap.cmj : bs_internalBucketsType.cmj bs_internalBuckets.cmj bs_Id.cmj \
bs_HashMapString.cmj bs_HashMapInt.cmj bs_Array.cmj bs_HashMap.cmi
bs_HashSet.cmj : bs_internalSetBuckets.cmj bs_internalBucketsType.cmj \
bs_HashSetString.cmj bs_HashSetInt.cmj bs_Dict.cmj bs_Array.cmj \
bs_Id.cmj bs_HashSetString.cmj bs_HashSetInt.cmj bs_Array.cmj \
bs_HashSet.cmi
bs_HashSetString.cmj : bs_internalSetBuckets.cmj bs_internalBucketsType.cmj \
bs_Array.cmj bs_HashSetString.cmi
bs_HashSetInt.cmj : bs_internalSetBuckets.cmj bs_internalBucketsType.cmj \
bs_Array.cmj bs_HashSetInt.cmi
bs_Dict.cmj : bs_Dict.cmi
bs_MapDict.cmj : bs_internalAVLtree.cmj bs_Dict.cmj bs_Array.cmj \
bs_Id.cmj : bs_Id.cmi
bs_MapDict.cmj : bs_internalAVLtree.cmj bs_Id.cmj bs_Array.cmj \
bs_MapDict.cmi
bs_SetDict.cmj : bs_internalAVLset.cmj bs_Dict.cmj bs_Array.cmj \
bs_SetDict.cmi
bs_Map.cmj : bs_MapString.cmj bs_MapInt.cmj bs_MapDict.cmj bs_Dict.cmj \
bs_SetDict.cmj : bs_internalAVLset.cmj bs_Id.cmj bs_Array.cmj bs_SetDict.cmi
bs_Map.cmj : bs_MapString.cmj bs_MapInt.cmj bs_MapDict.cmj bs_Id.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 \
Expand All @@ -56,17 +54,17 @@ bs_MapString.cmj : bs_internalMapString.cmj bs_internalAVLtree.cmj \
bs_Array.cmj bs_MapString.cmi
bs_MapInt.cmj : bs_internalMapInt.cmj bs_internalAVLtree.cmj bs_Array.cmj \
bs_MapInt.cmi
bs_Set.cmj : bs_SetString.cmj bs_SetInt.cmj bs_SetDict.cmj bs_Dict.cmj \
bs_Set.cmj : bs_SetString.cmj bs_SetInt.cmj bs_SetDict.cmj bs_Id.cmj \
bs_Array.cmj bs_Set.cmi
bs_MutableSet.cmj : bs_internalAVLset.cmj bs_SortArray.cmj \
bs_MutableSetString.cmj bs_MutableSetInt.cmj bs_Dict.cmj bs_Array.cmj \
bs_MutableSetString.cmj bs_MutableSetInt.cmj bs_Id.cmj bs_Array.cmj \
bs_MutableSet.cmi
bs_MutableSetInt.cmj : bs_internalSetInt.cmj bs_internalAVLset.cmj \
bs_SortArrayInt.cmj bs_Array.cmj
bs_MutableSetString.cmj : bs_internalSetString.cmj bs_internalAVLset.cmj \
bs_SortArrayString.cmj bs_Array.cmj bs_MutableSetString.cmi
bs_MutableMap.cmj : bs_internalAVLtree.cmj bs_MutableMapString.cmj \
bs_MutableMapInt.cmj bs_Dict.cmj bs_Array.cmj bs_MutableMap.cmi
bs_MutableMapInt.cmj bs_Id.cmj bs_Array.cmj bs_MutableMap.cmi
bs_MutableMapInt.cmj : bs_internalMapInt.cmj bs_internalAVLtree.cmj \
bs_Array.cmj bs_MutableMapInt.cmi
bs_MutableMapString.cmj : bs_internalMapString.cmj bs_internalAVLtree.cmj \
Expand Down Expand Up @@ -104,8 +102,8 @@ js_option.cmi :
js_result.cmi :
js_mapperRt.cmi :
bs_Array.cmi :
bs_internalAVLset.cmi : bs_Dict.cmi
bs_internalAVLtree.cmi : bs_Dict.cmi
bs_internalAVLset.cmi : bs_Id.cmi
bs_internalAVLtree.cmi : bs_Id.cmi
bs_List.cmi :
bs_SortArray.cmi : bs_SortArrayString.cmi bs_SortArrayInt.cmi
bs_SortArrayInt.cmi :
Expand All @@ -114,20 +112,20 @@ bs_Range.cmi :
bs_internalBucketsType.cmi :
bs_internalSetBuckets.cmi : bs_internalBucketsType.cmi
bs_internalBuckets.cmi : bs_internalBucketsType.cmi
bs_HashMap.cmi : bs_HashMapString.cmi bs_HashMapInt.cmi bs_Dict.cmi
bs_HashSet.cmi : bs_HashSetString.cmi bs_HashSetInt.cmi bs_Dict.cmi
bs_HashMap.cmi : bs_Id.cmi bs_HashMapString.cmi bs_HashMapInt.cmi
bs_HashSet.cmi : bs_Id.cmi bs_HashSetString.cmi bs_HashSetInt.cmi
bs_HashSetString.cmi :
bs_HashSetInt.cmi :
bs_Dict.cmi :
bs_MapDict.cmi : bs_Dict.cmi
bs_SetDict.cmi : bs_Dict.cmi
bs_Map.cmi : bs_MapString.cmi bs_MapInt.cmi bs_MapDict.cmi bs_Dict.cmi
bs_Id.cmi :
bs_MapDict.cmi : bs_Id.cmi
bs_SetDict.cmi : bs_Id.cmi
bs_Map.cmi : bs_MapString.cmi bs_MapInt.cmi bs_MapDict.cmi bs_Id.cmi
bs_MapString.cmi :
bs_MapInt.cmi :
bs_Set.cmi : bs_SetString.cmi bs_SetInt.cmi bs_SetDict.cmi bs_Dict.cmi
bs_MutableSet.cmi : bs_MutableSetString.cmi bs_MutableSetInt.cmj bs_Dict.cmi
bs_Set.cmi : bs_SetString.cmi bs_SetInt.cmi bs_SetDict.cmi bs_Id.cmi
bs_MutableSet.cmi : bs_MutableSetString.cmi bs_MutableSetInt.cmj bs_Id.cmi
bs_MutableSetString.cmi :
bs_MutableMap.cmi : bs_MutableMapString.cmi bs_MutableMapInt.cmi bs_Dict.cmi
bs_MutableMap.cmi : bs_MutableMapString.cmi bs_MutableMapInt.cmi bs_Id.cmi
bs_MutableMapInt.cmi :
bs_MutableMapString.cmi :
bs_SetInt.cmi :
Expand Down
2 changes: 1 addition & 1 deletion jscomp/others/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ SOURCE_LIST= node_path node_fs node_process dict node_module js_array js_string
bs_HashSet\
bs_HashSetString\
bs_HashSetInt\
bs_Dict\
bs_Id\
bs_MapDict\
bs_SetDict\
bs_Map\
Expand Down
19 changes: 10 additions & 9 deletions jscomp/others/bs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

(** A stdlib shipped with BuckleScript

This stdlib is still in beta status, but we encourage you to try it out and
This stdlib is still in {i beta} status, but we encourage you to try it out and
provide feedback.

{b Motivation }
Expand Down Expand Up @@ -70,29 +70,30 @@
{[
type t = int * int
module I0 =
(val Bs.Dict.comparableU ~cmp:(fun[\@bs] ((a0,a1) : t) ((b0,b1) : t) ->
(val Bs.Id.comparableU ~cmp:(fun[\@bs] ((a0,a1) : t) ((b0,b1) : t) ->
match compare a0 b0 with
| 0 -> compare a1 b1
| c -> c
))
let s0 = Bs.Set.make (module I0)
let s0 = Bs.Set.make ~id:(module I0)
module I1 =
(val Bs.Dict.comparableU ~cmp:(fun[\@bs] ((a0,a1) : t) ((b0,b1) : t) ->
(val Bs.Id.comparableU ~cmp:(fun[\@bs] ((a0,a1) : t) ((b0,b1) : t) ->
match compare a1 b1 with
| 0 -> compare a0 b0
| c -> c
))
let s1 = Bs.Set.make (module I1)
let s1 = Bs.Set.make ~id:(module I1)
]}

Here the compiler would infer [s0] and [s1] having different type so that
it would not mix.

{[
val s0 : Bs.Set.t ((int * int), I0.id)
val s1 : Bs.Set.t ((int * int), I1.id)
val s0 : Bs.Set.t ((int * int), I0.identity)
val s1 : Bs.Set.t ((int * int), I1.identity)
]}

[I0.identity] and [I1.identity] are not the same using our encoding scheme.

{b Collection Hierachy}

Expand All @@ -115,7 +116,7 @@

*)

(** {!Bs.Dict}
(** {!Bs.Id}

Provide utiliites to create identified comparators or hashes for
data structures used below.
Expand All @@ -124,7 +125,7 @@
functions so that different data structures with slightly different
comparison functions won't mix
*)
module Dict = Bs_Dict
module Id = Bs_Id

(** {!Bs.Array}

Expand Down
22 changes: 22 additions & 0 deletions jscomp/others/bs_Array.ml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,29 @@ let makeByAndShuffleU l f =

let makeByAndShuffle l f = makeByAndShuffleU l (fun[@bs] a -> f a)

let range start finish =
let cut = finish - start in
if cut < 0 then [||]
else
let arr = makeUninitializedUnsafe (cut + 1 ) in
for i = 0 to cut do
setUnsafe arr i (start + i)
done;
arr

let rangeBy start finish ~step =
let cut = finish - start in
if cut < 0 || step <=0 then
[||]
else
let nb = cut/step + 1 in
let arr = makeUninitializedUnsafe nb in
let cur = ref start in
for i = 0 to nb - 1 do
setUnsafe arr i !cur;
cur := !cur + step ;
done;
arr

let zip xs ys =
let lenx, leny = length xs, length ys in
Expand Down
25 changes: 25 additions & 0 deletions jscomp/others/bs_Array.mli
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,31 @@ val make: int -> 'a -> 'a array
@return an empty array when [n] is negative.
*)

val range: int -> int -> int array
(** [range start finish] create an inclusive array
@example {[
range 0 3 = [|0;1;2;3|];;
range 3 0 = [||] ;;
range 3 3 = [|3|];;
]}
*)
val rangeBy: int -> int -> step:int -> int array
(** [rangeBy start finish ~step]

@return empty array when step is 0 or negative
it also return empty array when [start > finish]

@example {[
rangeBy 0 10 ~step:3 = [|0;3;6;9|];;
rangeBy 0 12 ~step:3 = [|0;3;6;9;12|];;
rangeBy 33 0 ~step:1 = [||];;
rangeBy 33 0 ~step:(-1) = [||];;
rangeBy 3 12 ~step:(-1) = [||];;
rangeBy 3 3 ~step:0 = [||] ;;
rangeBy 3 3 ~step:(1) = [|3|] ;;
]}
*)

val makeByU: int -> (int -> 'a [@bs]) -> 'a array
val makeBy: int -> (int -> 'a ) -> 'a array
(** [makeBy n f]
Expand Down
36 changes: 0 additions & 36 deletions jscomp/others/bs_Bag.ml

This file was deleted.

6 changes: 0 additions & 6 deletions jscomp/others/bs_BagM.ml

This file was deleted.

26 changes: 13 additions & 13 deletions jscomp/others/bs_HashMap.ml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ module C = Bs_internalBucketsType
module A = Bs_Array


type ('a, 'id) eq = ('a, 'id) Bs_Dict.eq
type ('a, 'id) hash = ('a, 'id) Bs_Dict.hash
type ('a, 'id) dict = ('a, 'id) Bs_Dict.hashable
type ('a, 'id) eq = ('a, 'id) Bs_Id.eq
type ('a, 'id) hash = ('a, 'id) Bs_Id.hash
type ('a, 'id) dict = ('a, 'id) Bs_Id.hashable
type ('a,'b,'id) t =
( ('a, 'id) hash, ('a, 'id) eq, 'a, 'b) N.t

Expand Down Expand Up @@ -110,8 +110,8 @@ let set0 h key value ~eq ~hash =
*)
let set h key value =
set0 h key value
~eq:(Bs_Dict.getEqInternal (C.eq h))
~hash:(Bs_Dict.getHashInternal (C.hash h))
~eq:(Bs_Id.getEqInternal (C.eq h))
~hash:(Bs_Id.getHashInternal (C.hash h))

let rec removeInBucket h h_buckets i key prec bucket ~eq =
match C.toOpt bucket with
Expand All @@ -129,12 +129,12 @@ let rec removeInBucket h h_buckets i key prec bucket ~eq =

let remove h key =
let h_buckets = C.buckets h in
let i = (Bs_Dict.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in
let i = (Bs_Id.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in
let bucket = A.getUnsafe h_buckets i in
match C.toOpt bucket with
| None -> ()
| Some cell ->
let eq = (Bs_Dict.getEqInternal (C.eq h)) in
let eq = (Bs_Id.getEqInternal (C.eq h)) in
if eq (N.key cell ) key [@bs] then
begin
A.setUnsafe h_buckets i (N.next cell);
Expand All @@ -154,11 +154,11 @@ let rec getAux ~eq key buckets =

let get h key =
let h_buckets = C.buckets h in
let nid = (Bs_Dict.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in
let nid = (Bs_Id.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in
match C.toOpt @@ A.getUnsafe h_buckets nid with
| None -> None
| Some cell1 ->
let eq = Bs_Dict.getEqInternal (C.eq h) in
let eq = Bs_Id.getEqInternal (C.eq h) in
if eq key (N.key cell1) [@bs] then
Some (N.value cell1)
else
Expand All @@ -185,12 +185,12 @@ let rec memInBucket key cell ~eq =

let has h key =
let h_buckets = C.buckets h in
let nid = (Bs_Dict.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in
let nid = (Bs_Id.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in
let bucket = A.getUnsafe h_buckets nid in
match C.toOpt bucket with
| None -> false
| Some bucket ->
memInBucket ~eq:(Bs_Dict.getEqInternal (C.eq h)) key bucket
memInBucket ~eq:(Bs_Id.getEqInternal (C.eq h)) key bucket



Expand All @@ -205,15 +205,15 @@ let ofArray (type a) (type id) arr ~dict:(dict:(a,id) dict) =
let hash, eq = M.hash, M.eq in
let len = A.length arr in
let v = C.make ~hash ~eq len in
let eq, hash = Bs_Dict.getEqInternal eq, Bs_Dict.getHashInternal hash in
let eq, hash = Bs_Id.getEqInternal eq, Bs_Id.getHashInternal hash in
for i = 0 to len - 1 do
let key,value = (A.getUnsafe arr i) in
set0 ~eq ~hash v key value
done ;
v

let mergeMany h arr =
let hash, eq = Bs_Dict.getHashInternal ( C.hash h) , Bs_Dict.getEqInternal (C.eq h) in
let hash, eq = Bs_Id.getHashInternal ( C.hash h) , Bs_Id.getEqInternal (C.eq h) in
let len = A.length arr in
for i = 0 to len - 1 do
let key,value = (A.getUnsafe arr i) in
Expand Down
2 changes: 1 addition & 1 deletion jscomp/others/bs_HashMap.mli
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
type ('key,'value,'id) t
(** The type of hash tables from type ['key] to type ['value]. *)

type ('a, 'id) dict = ('a, 'id) Bs_Dict.hashable
type ('a, 'id) dict = ('a, 'id) Bs_Id.hashable


val make: int -> dict:('key, 'id) dict -> ('key,'value,'id) t
Expand Down
Loading