Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finalize api for hash #2460

Merged
merged 6 commits into from
Jan 23, 2018
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
2 changes: 1 addition & 1 deletion jscomp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ DOCS_SOURCES+=$(shell ls others/*.ml*)
ocamlopt.opt -I +compiler-libs -I +ocamldoc -shared -I ../odoc_gen -o $@ $^

docs: ../odoc_gen/generator.cmxs
make -C bin bsppx.exe
make -C ../lib bsppx.exe
node ../scripts/doc_gen.js
# ocamldoc.opt -nostdlib -I stdlib -g ../odoc_gen/generator.cmxs -charset utf-8 -css-style ../../odoc_gen/style.css -sort -ppx bin/bsppx.exe -I others -I runtime -d ../docs/api $(DOCS_SOURCES)

Expand Down
2 changes: 1 addition & 1 deletion jscomp/others/.depend
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ bs_internalBucketsType.cmi :
bs_internalSetBuckets.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_Bag.cmj
bs_HashSet.cmi : bs_Hash.cmi
bs_HashSetString.cmi :
bs_HashSetInt.cmi :
bs_Cmp.cmi :
Expand Down
4 changes: 2 additions & 2 deletions jscomp/others/bs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ module Queue = Bs_Queue
module HashMap = Bs_HashMap
module HashSet = Bs_HashSet
module HashSetInt = Bs_HashSetInt
module HashSetString = Bs_HashSetInt
module HashSetString = Bs_HashSetString
module HashMapString = Bs_HashMapString
module HashMultiMap = Bs_HashMultiMap
module HashMapInt = Bs_HashMapInt
module Sort = Bs_Sort
module SortInt = Bs_SortInt
Expand All @@ -53,3 +52,4 @@ module SetIntM = Bs_SetIntM
module SetString = Bs_SetString
module List = Bs_List

(* module HashMultiMap = Bs_HashMultiMap *)
47 changes: 33 additions & 14 deletions jscomp/others/bs_Array.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ external blitUnsafe :
(*DOC: when l < 0 raise RangeError js excpetion *)
(* See #6575. We could also check for maximum array size, but this depends
on whether we create a float array or a regular one... *)
let init l f =
let initExn l f =
[%assert l >= 0];
let res = makeUninitializedUnsafe l in
for i = 0 to l - 1 do
Expand All @@ -53,7 +53,7 @@ let shuffleDone xs =

let shuffle xs = shuffleDone xs; xs

let makeMatrix sx sy init =
let makeMatrixExn sx sy init =
[%assert sx >=0 && sy >=0 ];
let res = makeUninitializedUnsafe sx in
for x = 0 to sx - 1 do
Expand Down Expand Up @@ -91,29 +91,31 @@ let append a1 a2 =
else if length a2 = 0 then unsafe_sub a1 0 l1
else append_prim a1 a2

let sub a ofs len =
let subExn a ofs len =
if len < 0 || ofs > length a - len
then
(* invalid_arg *)
[%assert "Array.sub"]
[%assert "subExn"]
else unsafe_sub a ofs len

let fill a ofs len v =
if ofs < 0 || len < 0 || ofs > length a - len
then
(* invalid_arg *)
[%assert "Array.fill"]
else for i = ofs to ofs + len - 1 do unsafe_set a i v done
false
else
begin
for i = ofs to ofs + len - 1 do unsafe_set a i v done;
true
end

let blit a1 ofs1 a2 ofs2 len =
if len < 0 || ofs1 < 0 || ofs1 > length a1 - len
|| ofs2 < 0 || ofs2 > length a2 - len
then
(* invalid_arg *)
[%assert "Array.blit"]
else blitUnsafe a1 ofs1 a2 ofs2 len
false
else (blitUnsafe a1 ofs1 a2 ofs2 len; true)

let iter a f =
let forEach a f =
for i = 0 to length a - 1 do f(unsafe_get a i) [@bs] done

let map a f =
Expand All @@ -125,7 +127,7 @@ let map a f =
r


let iteri a f=
let forEachi a f=
for i = 0 to length a - 1 do f i (unsafe_get a i) [@bs] done

let mapi a f =
Expand Down Expand Up @@ -159,14 +161,14 @@ let ofList xs =
fillAUx a 0 xs;
a

let foldLeft a x f =
let reduce a x f =
let r = ref x in
for i = 0 to length a - 1 do
r := f !r (unsafe_get a i) [@bs]
done;
!r

let foldRight a x f =
let reduceFromTail a x f =
let r = ref x in
for i = length a - 1 downto 0 do
r := f !r (unsafe_get a i) [@bs]
Expand Down Expand Up @@ -200,6 +202,23 @@ let forAll2 a b p =
else
forAllAux2 a b 0 p lena

let eq = forAll2

let rec forAllCmpAux2 arr1 arr2 i b len =
if i = len then 0
else
let c = b (unsafe_get arr1 i) (unsafe_get arr2 i) [@bs] in
if c = 0 then
forAllCmpAux2 arr1 arr2 (i + 1) b len
else c

let cmp a b p =
let lena = length a in
let lenb = length b in
if lena > lenb then 1
else if lena < lenb then -1
else forAllCmpAux2 a b 0 p lena

external truncateToLengthUnsafe : 'a array -> int -> unit = "length" [@@bs.set]


Expand Down
68 changes: 35 additions & 33 deletions jscomp/others/bs_Array.mli
Original file line number Diff line number Diff line change
Expand Up @@ -37,79 +37,81 @@ external set : 'a array -> int -> 'a -> unit = "%array_safe_set"
external makeUninitialized : int -> 'a Js.undefined array = "Array" [@@bs.new]
external makeUninitializedUnsafe : int -> 'a array = "Array" [@@bs.new]

val init : int -> (int -> 'a [@bs]) -> 'a array
val initExn: int -> (int -> 'a [@bs]) -> 'a array

val shuffleDone : 'a array -> unit
val shuffleDone: 'a array -> unit

val shuffle :'a array -> 'a array
val shuffle: 'a array -> 'a array
(** [shuffle xs] it mutates [xs] and return
[xs] for chaining
*)
val zip : 'a array -> 'b array -> ('a * 'b) array
val zip: 'a array -> 'b array -> ('a * 'b) array
(** [zip a b] stop with the shorter array *)

val makeMatrix : int -> int -> 'a -> 'a array array
val makeMatrixExn: int -> int -> 'a -> 'a array array


val append : 'a array -> 'a array -> 'a array
val append: 'a array -> 'a array -> 'a array
(** Note it returns a fresh array containing the
concatenation of the arrays [v1] and [v2], so even if [v1] or [v2]
is empty, it can not be shared
*)

val concat : 'a array list -> 'a array
(** Same as [Array.append], but concatenates a list of arrays. *)
val concat: 'a array list -> 'a array

val sub : 'a array -> int -> int -> 'a array

val subExn: 'a array -> int -> int -> 'a array

val copy : 'a array -> 'a array
(** [Array.copy a] returns a copy of [a], that is, a fresh array

val copy: 'a array -> 'a array
(** [.copy a] returns a copy of [a], that is, a fresh array
containing the same elements as [a]. *)

val fill : 'a array -> int -> int -> 'a -> unit
(** [Array.fill a ofs len x] modifies the array [a] in place,
storing [x] in elements number [ofs] to [ofs + len - 1].
val fill: 'a array -> int -> int -> 'a -> bool
(** [fill a ofs len x] modifies the array [a] in place,
storing [x] in elements number [ofs] to [ofs + len - 1].

Raise [Invalid_argument "Array.fill"] if [ofs] and [len] do not
designate a valid subarray of [a]. *)
return false means the input is invalid, the array is unchanged
*)

val blit :
'a array -> int -> 'a array -> int -> int -> unit
val blit:
'a array -> int -> 'a array -> int -> int -> bool
(** [blit v1 o1 v2 o2 len] copies [len] elements
from array [v1], starting at element number [o1], to array [v2],
starting at element number [o2]. It works correctly even if
[v1] and [v2] are the same array, and the source and
destination chunks overlap.

Raise [Invalid_argument "Array.blit"] if [o1] and [len] do not
designate a valid subarray of [v1], or if [o2] and [len] do not
designate a valid subarray of [v2]. *)
external blitUnsafe :
return false means the input is invalid, the array is unchnaged
*)
external blitUnsafe:
'a array -> int -> 'a array -> int -> int -> unit = "caml_array_blit"

val toList : 'a array -> 'a list
val toList: 'a array -> 'a list


val ofList : 'a list -> 'a array
val ofList: 'a list -> 'a array

val iter : 'a array -> ('a -> unit [@bs]) -> unit
val forEach: 'a array -> ('a -> unit [@bs]) -> unit

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

val iteri : 'a array -> (int -> 'a -> unit [@bs]) -> unit
val forEachi: 'a array -> (int -> 'a -> unit [@bs]) -> unit

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

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

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

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

(** [forAll2 a b] return false when [length a <> length b] *)
val forAll2: 'a array -> 'b array -> ('a -> 'b -> bool [@bs]) -> bool

external unsafe_get : 'a array -> int -> 'a = "%array_unsafe_get"
external unsafe_set : 'a array -> int -> 'a -> unit = "%array_unsafe_set"
external truncateToLengthUnsafe : 'a array -> int -> unit = "length" [@@bs.set]
val cmp: 'a array -> 'a array -> ('a -> 'a -> int [@bs]) -> int
val eq: 'a array -> 'a array -> ('a -> 'a -> bool [@bs]) -> bool

external unsafe_get: 'a array -> int -> 'a = "%array_unsafe_get"
external unsafe_set: 'a array -> int -> 'a -> unit = "%array_unsafe_set"
external truncateToLengthUnsafe: 'a array -> int -> unit = "length" [@@bs.set]
Loading