Skip to content

Commit

Permalink
Merge 0af9bef into 93c4a6e
Browse files Browse the repository at this point in the history
  • Loading branch information
bobzhang committed Dec 21, 2017
2 parents 93c4a6e + 0af9bef commit 099cf7d
Show file tree
Hide file tree
Showing 55 changed files with 3,193 additions and 520 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -8,12 +8,12 @@ env:
- BS_TRAVIS_CI=1
node_js:
- 6

script: npm run coveralls
#
# - 6
# This delays notification

# Not a very reliable service..
# script: npm run coveralls

# FIXME: instrumentation takes too much time

26 changes: 19 additions & 7 deletions jscomp/others/.depend
Expand Up @@ -17,14 +17,22 @@ 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_internalAVLset.cmj : bs_Array.cmj bs.cmj
bs_internalAVLtree.cmj :
bs_internalMutableAVLSet.cmj : bs_internalAVLset.cmj
bs_Hash.cmj : bs_Hash.cmi
bs_Queue.cmj : bs_Array.cmj bs_Queue.cmi
bs_internalBuckets.cmj : bs_Array.cmj
bs_HashMap.cmj : bs_internalBuckets.cmj bs_Hash.cmj bs_Bag.cmj bs_Array.cmj \
bs_HashMap.cmi
bs_internalBucketsType.cmj : bs_Array.cmj
bs_internalSetBuckets.cmj : bs_internalBucketsType.cmj bs_Array.cmj bs.cmj
bs_internalBuckets.cmj : bs_internalBucketsType.cmj bs_Array.cmj
bs_HashMap.cmj : bs_internalBucketsType.cmj bs_internalBuckets.cmj \
bs_Hash.cmj bs_Bag.cmj bs_Array.cmj bs_HashMap.cmi
bs_HashSet.cmj : bs_internalSetBuckets.cmj bs_internalBucketsType.cmj \
bs_Hash.cmj bs_Bag.cmj bs_Array.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_Cmp.cmj : bs_Cmp.cmi
bs_Map.cmj : bs_internalAVLtree.cmj bs_Cmp.cmj bs_Bag.cmj bs_Array.cmj \
Expand All @@ -43,9 +51,10 @@ js_date.cmj :
js_global.cmj :
js_cast.cmj : js_cast.cmi
js_promise.cmj :
bs_HashMapInt.cmj : bs_internalBuckets.cmj bs_Array.cmj bs_HashMapInt.cmi
bs_HashMapString.cmj : bs_internalBuckets.cmj bs_Array.cmj \
bs_HashMapString.cmi
bs_HashMapInt.cmj : bs_internalBucketsType.cmj bs_internalBuckets.cmj \
bs_Array.cmj bs_HashMapInt.cmi
bs_HashMapString.cmj : bs_internalBucketsType.cmj bs_internalBuckets.cmj \
bs_Array.cmj bs_HashMapString.cmi
node_process.cmi : js_dict.cmi
js_re.cmi :
js_null_undefined.cmi :
Expand All @@ -60,6 +69,9 @@ bs_Array.cmi :
bs_Hash.cmi :
bs_Queue.cmi :
bs_HashMap.cmi : bs_Hash.cmi bs_Bag.cmj
bs_HashSet.cmi : bs_Hash.cmi bs_Bag.cmj
bs_HashSetString.cmi :
bs_HashSetInt.cmi :
bs_Cmp.cmi :
bs_Map.cmi : bs_Cmp.cmi bs_Bag.cmj
bs_Set.cmi : bs_Cmp.cmi bs_Bag.cmj
Expand Down
13 changes: 13 additions & 0 deletions jscomp/others/Makefile
Expand Up @@ -17,8 +17,13 @@ SOURCE_LIST= node_path node_fs node_process dict node_module js_array js_string
bs_internalMutableAVL\
bs_Hash\
bs_Queue\
bs_internalBucketsType\
bs_internalSetBuckets\
bs_internalBuckets\
bs_HashMap\
bs_HashSet\
bs_HashSetString\
bs_HashSetInt\
bs_Bag\
bs_Cmp\
bs_Map\
Expand Down Expand Up @@ -60,6 +65,14 @@ clean::
rm -f *.rawlambda *.lam *.lambda *.map

ifndef BS_RELEASE_BUILD
bs_HashSetString.ml: hashset.cppo.ml
cppo -D TYPE_STRING $^ > $@
bs_HashSetInt.ml: hashset.cppo.ml
cppo -D TYPE_INT $^ > $@
bs_HashSetString.mli: hashset.cppo.mli
cppo -D TYPE_STRING $^ > $@
bs_HashSetInt.mli: hashset.cppo.mli
cppo -D TYPE_INT $^ > $@
bs_HashMapString.ml: hashmap.cppo.ml
cppo -D TYPE_STRING $^ > $@
bs_HashMapInt.ml: hashmap.cppo.ml
Expand Down
3 changes: 3 additions & 0 deletions jscomp/others/bs.ml
Expand Up @@ -32,6 +32,9 @@ 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_HashSetInt
module HashMapString = Bs_HashMapString
module HashMapInt = Bs_HashMapInt
module Map = Bs_Map
Expand Down
26 changes: 24 additions & 2 deletions jscomp/others/bs_Bag.ml
@@ -1,6 +1,28 @@

(* Copyright (C) 2017 Authors of BuckleScript
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition to the permissions granted to you by the LGPL, you may combine
* or link a "work that uses the Library" with a publicly distributed version
* of this file to produce a combined library or application, then distribute
* that combined work under the terms of your choosing, with no requirement
* to comply with the obligations normally placed on you by section 4 of the
* LGPL version 3 (or the corresponding section of a later version of the LGPL
* should you choose to use a later version).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

type (+ 'k, + 'v) bag = {
dict : 'k ;
data : 'v
} [@@bs.deriving abstract]
} [@@bs.deriving abstract]
100 changes: 52 additions & 48 deletions jscomp/others/bs_HashMap.ml
Expand Up @@ -13,8 +13,9 @@
(** Adapted by Authors of BuckleScript 2017 *)

module N = Bs_internalBuckets
module C = Bs_internalBucketsType
module B = Bs_Bag
type ('a, 'b,'id) t0 = ('a,'b,'id) N.t0
type ('a, 'b,'id) t0 = ('a,'b) N.t0


type ('a,'b) bucket = ('a,'b) N.bucket
Expand All @@ -26,12 +27,12 @@ type ('a,'b,'id) t =


let rec insert_bucket ~hash ~h_buckets ~ndata_tail h old_bucket =
match N.toOpt old_bucket with
match C.toOpt old_bucket with
| None -> ()
| Some cell ->
let nidx = (Bs_Hash.getHash hash) (N.key cell) [@bs] land (Array.length h_buckets - 1) in
let v = N.return cell in
begin match N.toOpt (Bs_Array.unsafe_get ndata_tail nidx) with
let v = C.return cell in
begin match C.toOpt (Bs_Array.unsafe_get ndata_tail nidx) with
| None ->
Bs_Array.unsafe_set h_buckets nidx v
| Some tail ->
Expand All @@ -42,101 +43,101 @@ let rec insert_bucket ~hash ~h_buckets ~ndata_tail h old_bucket =


let resize ~hash h =
let odata = N.buckets h in
let odata = C.buckets h in
let osize = Array.length odata in
let nsize = osize * 2 in
if nsize >= osize then begin (* no overflow *)
let h_buckets = N.makeSize nsize in
let ndata_tail = N.makeSize nsize in (* keep track of tail *)
N.bucketsSet h h_buckets; (* so that indexfun sees the new bucket count *)
let h_buckets = C.makeSize nsize in
let ndata_tail = C.makeSize nsize in (* keep track of tail *)
C.bucketsSet h h_buckets; (* so that indexfun sees the new bucket count *)
for i = 0 to osize - 1 do
insert_bucket ~hash ~h_buckets ~ndata_tail h (Bs_Array.unsafe_get odata i)
done;
for i = 0 to nsize - 1 do
match N.toOpt (Bs_Array.unsafe_get ndata_tail i) with
match C.toOpt (Bs_Array.unsafe_get ndata_tail i) with
| None -> ()
| Some tail -> N.nextSet tail N.emptyOpt
| Some tail -> N.nextSet tail C.emptyOpt
done
end


let add0 ~hash h key value =
let h_buckets = N.buckets h in
let h_buckets = C.buckets h in
let h_buckets_lenth = Array.length h_buckets in
let i = (Bs_Hash.getHash hash) key [@bs] land (h_buckets_lenth - 1) in
let bucket =
N.bucket ~key ~value ~next:(Bs_Array.unsafe_get h_buckets i) in
Bs_Array.unsafe_set h_buckets i (N.return bucket);
let h_new_size = N.size h + 1 in
N.sizeSet h h_new_size;
Bs_Array.unsafe_set h_buckets i (C.return bucket);
let h_new_size = C.size h + 1 in
C.sizeSet h h_new_size;
if h_new_size > h_buckets_lenth lsl 1 then resize ~hash h


let rec remove_bucket ~eq h h_buckets i key prec buckets =
match N.toOpt buckets with
match C.toOpt buckets with
| None -> ()
| Some cell ->
let cell_next = N.next cell in
if (Bs_Hash.getEq eq) (N.key cell) key [@bs]
then
begin
(match N.toOpt prec with
(match C.toOpt prec with
| None -> Bs_Array.unsafe_set h_buckets i cell_next
| Some c -> N.nextSet c cell_next);
N.sizeSet h (N.size h - 1);
C.sizeSet h (C.size h - 1);
end
else remove_bucket ~eq h h_buckets i key buckets cell_next

let remove0 ~hash ~eq h key =
let h_buckets = N.buckets h in
let h_buckets = C.buckets h in
let i = (Bs_Hash.getHash hash) key [@bs] land (Array.length h_buckets - 1) in
remove_bucket ~eq h h_buckets i key N.emptyOpt (Bs_Array.unsafe_get h_buckets i)
remove_bucket ~eq h h_buckets i key C.emptyOpt (Bs_Array.unsafe_get h_buckets i)

let rec removeAllBuckets ~eq h h_buckets i key prec buckets =
match N.toOpt buckets with
match C.toOpt buckets with
| None -> ()
| Some cell ->
let cell_next = N.next cell in
if (Bs_Hash.getEq eq) (N.key cell) key [@bs]
then
begin
(match N.toOpt prec with
(match C.toOpt prec with
| None -> Bs_Array.unsafe_set h_buckets i cell_next
| Some c -> N.nextSet c cell_next);
N.sizeSet h (N.size h - 1);
C.sizeSet h (C.size h - 1);
end;
removeAllBuckets ~eq h h_buckets i key buckets cell_next

let removeAll0 ~hash ~eq h key =
let h_buckets = N.buckets h in
let h_buckets = C.buckets h in
let i = (Bs_Hash.getHash hash) key [@bs] land (Array.length h_buckets - 1) in
removeAllBuckets ~eq h h_buckets i key N.emptyOpt (Bs_Array.unsafe_get h_buckets i)
removeAllBuckets ~eq h h_buckets i key C.emptyOpt (Bs_Array.unsafe_get h_buckets i)


let rec find_rec ~eq key buckets =
match N.toOpt buckets with
match C.toOpt buckets with
| None ->
None
| Some cell ->
if (Bs_Hash.getEq eq) key (N.key cell) [@bs] then Some (N.value cell)
else find_rec ~eq key (N.next cell)

let findOpt0 ~hash ~eq h key =
let h_buckets = N.buckets h in
let h_buckets = C.buckets h in
let nid = (Bs_Hash.getHash hash) key [@bs] land (Array.length h_buckets - 1) in
match N.toOpt @@ Bs_Array.unsafe_get h_buckets nid with
match C.toOpt @@ Bs_Array.unsafe_get h_buckets nid with
| None -> None
| Some cell1 ->
if (Bs_Hash.getEq eq) key (N.key cell1) [@bs] then
Some (N.value cell1)
else
match N.toOpt (N.next cell1) with
match C.toOpt (N.next cell1) with
| None -> None
| Some cell2 ->
if (Bs_Hash.getEq eq) key
(N.key cell2) [@bs] then
Some (N.value cell2) else
match N.toOpt (N.next cell2) with
match C.toOpt (N.next cell2) with
| None -> None
| Some cell3 ->
if (Bs_Hash.getEq eq) key
Expand All @@ -148,20 +149,20 @@ let findOpt0 ~hash ~eq h key =

let findAll0 ~hash ~eq h key =
let rec find_in_bucket buckets =
match N.toOpt buckets with
match C.toOpt buckets with
| None ->
[]
| Some cell ->
if (Bs_Hash.getEq eq)
(N.key cell) key [@bs]
then (N.value cell) :: find_in_bucket (N.next cell)
else find_in_bucket (N.next cell) in
let h_buckets = N.buckets h in
let h_buckets = C.buckets h in
let nid = (Bs_Hash.getHash hash) key [@bs] land (Array.length h_buckets - 1) in
find_in_bucket (Bs_Array.unsafe_get h_buckets nid)

let rec replace_bucket ~eq key info buckets =
match N.toOpt buckets with
match C.toOpt buckets with
| None ->
true
| Some cell ->
Expand All @@ -176,36 +177,39 @@ let rec replace_bucket ~eq key info buckets =
replace_bucket ~eq key info (N.next cell)

let replace0 ~hash ~eq h key info =
let h_buckets = N.buckets h in
let h_buckets = C.buckets h in
let i = (Bs_Hash.getHash hash) key [@bs] land (Array.length h_buckets - 1) in
let l = Array.unsafe_get h_buckets i in
if replace_bucket ~eq key info l then begin
Bs_Array.unsafe_set h_buckets i (N.return
Bs_Array.unsafe_set h_buckets i (C.return
(N.bucket ~key ~value:info ~next:l));
N.sizeSet h (N.size h + 1);
if N.size h > Array.length (N.buckets h) lsl 1 then resize ~hash h
C.sizeSet h (C.size h + 1);
if C.size h > Array.length (C.buckets h) lsl 1 then resize ~hash h
(* TODO: duplicate bucklets ? *)
end

let rec mem_in_bucket ~eq key buckets =
match N.toOpt buckets with
| None ->
false
| Some cell ->
let rec mem_in_bucket ~eq key cell =
(Bs_Hash.getEq eq)
(N.key cell) key [@bs] ||
mem_in_bucket ~eq key (N.next cell)
(match C.toOpt (N.next cell) with
| None -> false
| Some nextCell ->
mem_in_bucket ~eq key nextCell)

let mem0 ~hash ~eq h key =
let h_buckets = N.buckets h in
let h_buckets = C.buckets h in
let nid = (Bs_Hash.getHash hash) key [@bs] land (Array.length h_buckets - 1) in
mem_in_bucket ~eq key (Bs_Array.unsafe_get h_buckets nid)
let bucket = (Bs_Array.unsafe_get h_buckets nid) in
match C.toOpt bucket with
| None -> false
| Some bucket ->
mem_in_bucket ~eq key bucket


let create0 = N.create0
let clear0 = N.clear0
let reset0 = N.reset0
let length0 = N.length0
let create0 = C.create0
let clear0 = C.clear0
let reset0 = C.reset0
let length0 = C.length0
let iter0 = N.iter0
let fold0 = N.fold0
let logStats0 = N.logStats0
Expand Down

0 comments on commit 099cf7d

Please sign in to comment.