Skip to content

Commit d21a3d9

Browse files
committed
part 2: finishing hashMap, todo: clean up Array, add specialized HashMapString/Int
1 parent 6fdd23c commit d21a3d9

33 files changed

+861
-306
lines changed

jscomp/core/lam_dispatch_primitive.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -763,6 +763,10 @@ let translate loc (prim_name : string)
763763
end
764764
| "caml_md5_string"
765765
-> call Js_runtime_modules.md5
766+
| "caml_hash_mix_string"
767+
| "caml_hash_mix_int"
768+
| "caml_hash_final_mix"
769+
766770
| "caml_hash"
767771
-> call Js_runtime_modules.hash
768772
| "caml_weak_set"

jscomp/others/.depend

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ js_obj.cmj :
1313
js_vector.cmj : js_array.cmj js_vector.cmi
1414
js_list.cmj : js_vector.cmj js_list.cmi
1515
js_option.cmj : js_option.cmi
16+
js_console.cmj :
1617
js_result.cmj : js_result.cmi
1718
js_mapperRt.cmj : js_mapperRt.cmi
1819
bs_Array.cmj : bs_Array.cmi

jscomp/others/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ MAP_FILES= node bs
66

77
SOURCE_LIST= node_path node_fs node_process dict node_module js_array js_string \
88
js_re js_null_undefined node_buffer js_types js_json js_obj \
9-
js_vector js_list js_option js_result\
9+
js_vector js_list js_option \
10+
js_console\
11+
js_result\
1012
js_mapperRt\
1113
bs_Array\
1214
bs_internalAVLset\
@@ -28,7 +30,7 @@ $(addsuffix .cmj, $(SOURCE_LIST)): $(addsuffix .cmj, $(MAP_FILES))
2830

2931
RUNTIME := $(addsuffix .cmj, $(SOURCE_LIST)) $(addsuffix .cmi, $(SOURCE_LIST))
3032

31-
BS_COMMON_FLAGS= -no-alias-deps -bs-no-version-header -absname -bs-diagnose -bs-no-check-div-by-zero -bs-cross-module-opt -bs-noassertfalse -bs-package-name bs-platform
33+
BS_COMMON_FLAGS= -no-alias-deps -bs-no-version-header -absname -bs-diagnose -bs-no-check-div-by-zero -bs-cross-module-opt -bs-noassertfalse -bs-package-name bs-platform
3234

3335

3436
BS_FLAGS= $(BS_COMMON_FLAGS) $(BS_PKG_FLAGS)

jscomp/others/bs.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
module Cmp = Bs_Cmp
3131
module Hash = Bs_Hash
3232
module Array = Bs_Array
33+
module HashMap = Bs_HashMap
3334
module Map = Bs_Map
3435
module Set = Bs_Set
3536
module MapInt = Bs_MapInt

jscomp/others/bs_Array.ml

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,30 @@ external append_prim : 'a array -> 'a array -> 'a array = "caml_array_append"
2525
external concat : 'a array list -> 'a array = "caml_array_concat"
2626
external unsafe_blit :
2727
'a array -> int -> 'a array -> int -> int -> unit = "caml_array_blit"
28-
external make_float: int -> float array = "caml_make_float_vect"
28+
external makeFloat: int -> float array = "caml_make_float_vect"
2929

30+
(*DOC: when l < 0 raise RangeError js excpetion *)
3031
let init l f =
3132
if l = 0 then [||] else
32-
if l < 0 then invalid_arg "Array.init"
3333
(* See #6575. We could also check for maximum array size, but this depends
3434
on whether we create a float array or a regular one... *)
35-
else
35+
(* if l < 0 then invalid_arg "Array.init"
36+
37+
else *)
3638
let res = create l (f 0 [@bs]) in
3739
for i = 1 to pred l do
3840
unsafe_set res i (f i [@bs])
3941
done;
4042
res
4143

42-
let make_matrix sx sy init =
44+
let makeMatrix sx sy init =
4345
let res = create sx [||] in
4446
for x = 0 to pred sx do
4547
unsafe_set res x (create sy init)
4648
done;
4749
res
4850

49-
let create_matrix = make_matrix
51+
5052

5153
let copy a =
5254
let l = length a in if l = 0 then [||] else unsafe_sub a 0 l
@@ -59,18 +61,24 @@ let append a1 a2 =
5961

6062
let sub a ofs len =
6163
if len < 0 || ofs > length a - len
62-
then invalid_arg "Array.sub"
64+
then
65+
(* invalid_arg *)
66+
[%assert "Array.sub"]
6367
else unsafe_sub a ofs len
6468

6569
let fill a ofs len v =
6670
if ofs < 0 || len < 0 || ofs > length a - len
67-
then invalid_arg "Array.fill"
71+
then
72+
(* invalid_arg *)
73+
[%assert "Array.fill"]
6874
else for i = ofs to ofs + len - 1 do unsafe_set a i v done
6975

7076
let blit a1 ofs1 a2 ofs2 len =
7177
if len < 0 || ofs1 < 0 || ofs1 > length a1 - len
7278
|| ofs2 < 0 || ofs2 > length a2 - len
73-
then invalid_arg "Array.blit"
79+
then
80+
(* invalid_arg *)
81+
[%assert "Array.blit"]
7482
else unsafe_blit a1 ofs1 a2 ofs2 len
7583

7684
let iter f a =
@@ -99,7 +107,7 @@ let mapi f a =
99107
r
100108
end
101109

102-
let to_list a =
110+
let toList a =
103111
let rec tolist i res =
104112
if i < 0 then res else tolist (i - 1) (unsafe_get a i :: res) in
105113
tolist (length a - 1) []
@@ -110,7 +118,7 @@ let rec list_length accu = function
110118
| h::t -> list_length (succ accu) t
111119
;;
112120

113-
let of_list = function
121+
let ofList = function
114122
[] -> [||]
115123
| hd::tl as l ->
116124
let a = create (list_length 0 l) hd in
@@ -119,14 +127,14 @@ let of_list = function
119127
| hd::tl -> unsafe_set a i hd; fill (i+1) tl in
120128
fill 1 tl
121129

122-
let fold_left f x a =
130+
let foldLeft f x a =
123131
let r = ref x in
124132
for i = 0 to length a - 1 do
125133
r := f !r (unsafe_get a i) [@bs]
126134
done;
127135
!r
128136

129-
let fold_right f a x =
137+
let foldRight f a x =
130138
let r = ref x in
131139
for i = length a - 1 downto 0 do
132140
r := f (unsafe_get a i) !r [@bs]
@@ -184,7 +192,7 @@ let sort cmp a =
184192
;;
185193

186194
let cutoff = 5;;
187-
let stable_sort cmp a =
195+
let stableSort cmp a =
188196
let merge src1ofs src1len src2 src2ofs src2len dst dstofs =
189197
let src1r = src1ofs + src1len and src2r = src2ofs + src2len in
190198
let rec loop i1 s1 i2 s2 d =
@@ -236,4 +244,4 @@ let stable_sort cmp a =
236244
end;
237245
;;
238246

239-
let fast_sort = stable_sort;;
247+
let fastSort = stableSort;;

jscomp/others/bs_Array.mli

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ val init : int -> (int -> 'a [@bs]) -> 'a array
5757
If the return type of [f] is [float], then the maximum
5858
size is only [Sys.max_array_length / 2].*)
5959

60-
val make_matrix : int -> int -> 'a -> 'a array array
60+
val makeMatrix : int -> int -> 'a -> 'a array array
6161
(** [Array.make_matrix dimx dimy e] returns a two-dimensional array
6262
(an array of arrays) with first dimension [dimx] and
6363
second dimension [dimy]. All the elements of this new matrix
@@ -109,10 +109,10 @@ val blit : 'a array -> int -> 'a array -> int -> int -> unit
109109
designate a valid subarray of [v1], or if [o2] and [len] do not
110110
designate a valid subarray of [v2]. *)
111111

112-
val to_list : 'a array -> 'a list
112+
val toList : 'a array -> 'a list
113113
(** [Array.to_list a] returns the list of all the elements of [a]. *)
114114

115-
val of_list : 'a list -> 'a array
115+
val ofList : 'a list -> 'a array
116116
(** [Array.of_list l] returns a fresh array containing the elements
117117
of [l]. *)
118118

@@ -136,17 +136,17 @@ val mapi : (int -> 'a -> 'b [@bs]) -> 'a array -> 'b array
136136
function is applied to the index of the element as first argument,
137137
and the element itself as second argument. *)
138138

139-
val fold_left : ('a -> 'b -> 'a [@bs]) -> 'a -> 'b array -> 'a
139+
val foldLeft : ('a -> 'b -> 'a [@bs]) -> 'a -> 'b array -> 'a
140140
(** [Array.fold_left f x a] computes
141141
[f (... (f (f x a.(0)) a.(1)) ...) a.(n-1)],
142142
where [n] is the length of the array [a]. *)
143143

144-
val fold_right : ('b -> 'a -> 'a [@bs]) -> 'b array -> 'a -> 'a
144+
val foldRight : ('b -> 'a -> 'a [@bs]) -> 'b array -> 'a -> 'a
145145
(** [Array.fold_right f a x] computes
146146
[f a.(0) (f a.(1) ( ... (f a.(n-1) x) ...))],
147147
where [n] is the length of the array [a]. *)
148148

149-
external make_float: int -> float array = "caml_make_float_vect"
149+
external makeFloat: int -> float array = "caml_make_float_vect"
150150
(** [Array.make_float n] returns a fresh float array of length [n],
151151
with uninitialized data.
152152
@since 4.02 *)
@@ -180,7 +180,7 @@ val sort : ('a -> 'a -> int [@bs]) -> 'a array -> unit
180180
- [cmp a.(i) a.(j)] >= 0 if and only if i >= j
181181
*)
182182

183-
val stable_sort : ('a -> 'a -> int [@bs]) -> 'a array -> unit
183+
val stableSort : ('a -> 'a -> int [@bs]) -> 'a array -> unit
184184
(** Same as {!Array.sort}, but the sorting algorithm is stable (i.e.
185185
elements that compare equal are kept in their original order) and
186186
not guaranteed to run in constant heap space.
@@ -190,7 +190,7 @@ val stable_sort : ('a -> 'a -> int [@bs]) -> 'a array -> unit
190190
It is usually faster than the current implementation of {!Array.sort}.
191191
*)
192192

193-
val fast_sort : ('a -> 'a -> int [@bs]) -> 'a array -> unit
193+
val fastSort : ('a -> 'a -> int [@bs]) -> 'a array -> unit
194194
(** Same as {!Array.sort} or {!Array.stable_sort}, whichever is faster
195195
on typical input.
196196
*)

0 commit comments

Comments
 (0)