Skip to content

Commit d703a9e

Browse files
committed
clean up with more tests
1 parent 534547d commit d703a9e

17 files changed

+1002
-843
lines changed

jscomp/Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,15 @@ common/bs_version.ml: build_version.js ../package.json
112112
STUB_SRCS = bs_hash_stubs
113113
OUNIT_SRCS = oUnit oUnitDiff oUnitLogger oUnitTypes oUnitUtils oUnitChooser
114114
OUNIT_CMXS = $(addprefix ounit/, $(addsuffix .cmx, $(OUNIT_SRCS)))
115-
OUNIT_TESTS_SRCS = ounit_tests_util ounit_array_tests ounit_list_test ounit_bal_tree_tests ounit_path_tests ounit_union_find_tests ounit_hash_stubs_test ounit_hash_set_tests ounit_scc_tests ounit_json_tests ounit_map_tests ounit_vec_test ounit_tests_main
115+
OUNIT_TESTS_SRCS = ounit_tests_util \
116+
ounit_array_tests ounit_list_test \
117+
ounit_bal_tree_tests ounit_path_tests \
118+
ounit_union_find_tests ounit_hash_stubs_test \
119+
ounit_hash_set_tests ounit_scc_tests \
120+
ounit_json_tests ounit_map_tests \
121+
ounit_ordered_hash_set_tests \
122+
ounit_vec_test \
123+
ounit_tests_main
116124
OUNIT_TESTS_CMXS = $(addprefix ounit_tests/, $(addsuffix .cmx, $(OUNIT_TESTS_SRCS)))
117125

118126
EXT_SRCS = ext_util\
@@ -137,6 +145,7 @@ EXT_SRCS = ext_util\
137145
hash_set_gen hash_set string_hash_set int_hash_set \
138146
ordered_hash_set_gen\
139147
ordered_hash_set_string\
148+
ordered_hash_set_make\
140149
ordered_hash_map_gen\
141150
union_find \
142151
ext_ident\

jscomp/all.depend

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ ext/int_hash_set.cmx : ext/hash_set_gen.cmx ext/ext_int.cmx \
3636
stubs/bs_hash_stubs.cmx ext/int_hash_set.cmi
3737
ext/ordered_hash_set_gen.cmx : ext/ext_util.cmx
3838
ext/ordered_hash_set_string.cmx : ext/ordered_hash_set_gen.cmx \
39-
ext/ext_string.cmx stubs/bs_hash_stubs.cmx
39+
ext/ext_string.cmx stubs/bs_hash_stubs.cmx \
40+
ext/ordered_hash_set_string.cmi
41+
ext/ordered_hash_set_make.cmx : ext/ordered_hash_set_gen.cmx
4042
ext/ordered_hash_map_gen.cmx : ext/ext_util.cmx
4143
ext/union_find.cmx : ext/union_find.cmi
4244
ext/ext_ident.cmx : ext/string_hashtbl.cmx ext/string_hash_set.cmx \
@@ -91,6 +93,7 @@ ext/ext_sys.cmi :
9193
ext/hash_set.cmi : ext/hash_set_gen.cmx
9294
ext/string_hash_set.cmi : ext/hash_set_gen.cmx
9395
ext/int_hash_set.cmi : ext/hash_set_gen.cmx
96+
ext/ordered_hash_set_string.cmi : ext/ordered_hash_set_gen.cmx
9497
ext/union_find.cmi :
9598
ext/ext_ident.cmi :
9699
ext/ident_map.cmi : ext/map_gen.cmx
@@ -555,6 +558,7 @@ ounit_tests/ounit_scc_tests.cmx : ounit/oUnit.cmx ext/int_vec_vec.cmx \
555558
ounit_tests/ounit_json_tests.cmx : ext/string_map.cmx ounit/oUnit.cmx \
556559
bsb/bsb_json.cmx
557560
ounit_tests/ounit_map_tests.cmx : ounit/oUnit.cmx ext/int_map.cmx
561+
ounit_tests/ounit_ordered_hash_set_tests.cmx : ounit/oUnit.cmx
558562
ounit_tests/ounit_vec_test.cmx : ounit/oUnit.cmx ext/int_vec.cmx \
559563
bsb/bsb_json.cmx
560564
ounit_tests/ounit_tests_main.cmx : ext/resize_array.cmx \

jscomp/bin/all_ounit_tests.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ bin/all_ounit_tests.ml : ext/hash_set_poly.mli
2929
bin/all_ounit_tests.ml : stubs/bs_hash_stubs.ml
3030
bin/all_ounit_tests.ml : ext/ordered_hash_set_gen.ml
3131
bin/all_ounit_tests.ml : ext/ordered_hash_set_string.ml
32+
bin/all_ounit_tests.ml : ext/ordered_hash_set_string.mli
3233
bin/all_ounit_tests.ml : ext/string_hash_set.ml
3334
bin/all_ounit_tests.ml : ext/string_hash_set.mli
3435
bin/all_ounit_tests.ml : ounit_tests/ounit_hash_set_tests.ml

jscomp/bin/all_ounit_tests.ml

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3644,12 +3644,11 @@ sig
36443644
val copy: t -> t
36453645
val add : t -> key -> unit
36463646
val mem : t -> key -> bool
3647-
val find : t -> key -> int (* -1 if not found*)
3647+
val rank : t -> key -> int (* -1 if not found*)
36483648
val iter: (key -> int -> unit) -> t -> unit
36493649
val fold: (key -> int -> 'b -> 'b) -> t -> 'b -> 'b
36503650
val length: t -> int
36513651
val stats: t -> Hashtbl.statistics
3652-
val elements : t -> key list
36533652
val choose : t -> key
36543653
val to_sorted_array: t -> key array
36553654
end
@@ -3707,17 +3706,20 @@ let resize indexfun h =
37073706
done
37083707
end
37093708

3709+
3710+
let rec do_bucket f = function
3711+
| Empty ->
3712+
()
3713+
| Cons(k ,i, rest) ->
3714+
f k i ; do_bucket f rest
3715+
37103716
let iter f h =
3711-
let rec do_bucket = function
3712-
| Empty ->
3713-
()
3714-
| Cons(k ,i, rest) ->
3715-
f k i ; do_bucket rest in
37163717
let d = h.data in
37173718
for i = 0 to Array.length d - 1 do
3718-
do_bucket (Array.unsafe_get d i)
3719+
do_bucket f (Array.unsafe_get d i)
37193720
done
37203721

3722+
(* find one element *)
37213723
let choose h =
37223724
let rec aux arr offset len =
37233725
if offset >= len then raise Not_found
@@ -3728,14 +3730,6 @@ let choose h =
37283730
in
37293731
aux h.data 0 (Array.length h.data)
37303732

3731-
let to_sorted_array h =
3732-
if h.size = 0 then [||]
3733-
else
3734-
let v = choose h in
3735-
let arr = Array.make h.size v in
3736-
iter (fun k i -> Array.unsafe_set arr i k) h;
3737-
arr
3738-
37393733
let fold f h init =
37403734
let rec do_bucket b accu =
37413735
match b with
@@ -3750,8 +3744,17 @@ let fold f h init =
37503744
done;
37513745
!accu
37523746

3753-
let elements set =
3754-
fold (fun k i acc -> k :: acc) set []
3747+
3748+
3749+
let to_sorted_array h =
3750+
if h.size = 0 then [||]
3751+
else
3752+
let v = choose h in
3753+
let arr = Array.make h.size v in
3754+
iter (fun k i -> Array.unsafe_set arr i k) h;
3755+
arr
3756+
3757+
37553758

37563759

37573760
let rec bucket_length acc (x : _ bucket) =
@@ -3775,8 +3778,14 @@ let stats h =
37753778

37763779

37773780
end
3778-
module Ordered_hash_set_string
3779-
= struct
3781+
module Ordered_hash_set_string : sig
3782+
#1 "ordered_hash_set_string.mli"
3783+
3784+
3785+
3786+
3787+
include Ordered_hash_set_gen.S with type key = string
3788+
end = struct
37803789
#1 "ordered_hash_set_string.ml"
37813790

37823791

@@ -3798,7 +3807,6 @@ let iter = iter
37983807
let fold = fold
37993808
let length = length
38003809
let stats = stats
3801-
let elements = elements
38023810
let choose = choose
38033811
let to_sorted_array = to_sorted_array
38043812

@@ -3819,7 +3827,7 @@ let rec small_bucket_mem key lst =
38193827
equal_key key key3 ||
38203828
small_bucket_mem key rest
38213829

3822-
let rec small_bucket_find key lst =
3830+
let rec small_bucket_rank key lst =
38233831
match lst with
38243832
| Empty -> -1
38253833
| Cons(key1,i,rest) ->
@@ -3832,7 +3840,7 @@ let rec small_bucket_find key lst =
38323840
| Empty -> -1
38333841
| Cons(key3,i3, rest) ->
38343842
if equal_key key key3 then i3 else
3835-
small_bucket_find key rest
3843+
small_bucket_rank key rest
38363844
let add h key =
38373845
let i = key_index h key in
38383846
if not (small_bucket_mem key h.data.(i)) then
@@ -3842,10 +3850,19 @@ let add h key =
38423850
if h.size > Array.length h.data lsl 1 then resize key_index h
38433851
end
38443852

3853+
let of_array arr =
3854+
let len = Array.length arr in
3855+
let h = create len in
3856+
for i = 0 to len - 1 do
3857+
add h (Array.unsafe_get arr i)
3858+
done;
3859+
h
3860+
3861+
38453862
let mem h key =
38463863
small_bucket_mem key (Array.unsafe_get h.data (key_index h key))
3847-
let find h key =
3848-
small_bucket_find key (Array.unsafe_get h.data (key_index h key))
3864+
let rank h key =
3865+
small_bucket_rank key (Array.unsafe_get h.data (key_index h key))
38493866

38503867

38513868

0 commit comments

Comments
 (0)