Skip to content

Commit

Permalink
Merge 60faf06 into 9312d17
Browse files Browse the repository at this point in the history
  • Loading branch information
bobzhang committed Jan 12, 2018
2 parents 9312d17 + 60faf06 commit bd01da6
Show file tree
Hide file tree
Showing 19 changed files with 191 additions and 36 deletions.
9 changes: 5 additions & 4 deletions jscomp/others/.depend
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ bs_Queue.cmj : bs_Array.cmj bs_Queue.cmi
bs_List.cmj : js_json.cmj bs_Array.cmj bs_List.cmi
bs_Sort.cmj : bs_Array.cmj bs_Sort.cmi
bs_Range.cmj :
bs_internalBucketsType.cmj : bs_Array.cmj
bs_internalSetBuckets.cmj : bs_internalBucketsType.cmj bs_Array.cmj bs.cmj
bs_internalBucketsType.cmj : bs_Array.cmj bs_internalBucketsType.cmi
bs_internalSetBuckets.cmj : bs_internalBucketsType.cmj bs_Array.cmj bs.cmj \
bs_internalSetBuckets.cmi
bs_internalBuckets.cmj : bs_internalBucketsType.cmj bs_Array.cmj bs.cmj
bs_HashMap.cmj : bs_internalBucketsType.cmj bs_internalBuckets.cmj \
bs_Hash.cmj bs_Bag.cmj bs_Array.cmj bs.cmj bs_HashMap.cmi
Expand All @@ -46,7 +47,6 @@ bs_Map.cmj : bs_internalAVLtree.cmj bs_Cmp.cmj bs_Bag.cmj bs_Array.cmj \
bs_Map.cmi
bs_MapString.cmj : bs_internalAVLtree.cmj bs_Array.cmj bs_MapString.cmi
bs_MapInt.cmj : bs_internalAVLtree.cmj bs_Array.cmj bs_MapInt.cmi
bs_internalSet.cmj : bs_internalSet.cmi
bs_Set.cmj : bs_internalAVLset.cmj bs_Cmp.cmj bs_Bag.cmj bs_Array.cmj \
bs_Set.cmi
bs_SetM.cmj : bs_internalAVLset.cmj bs_Sort.cmj bs_Cmp.cmj bs_BagM.cmj \
Expand Down Expand Up @@ -93,6 +93,8 @@ bs_Hash.cmi :
bs_Queue.cmi :
bs_List.cmi : js_json.cmi
bs_Sort.cmi :
bs_internalBucketsType.cmi :
bs_internalSetBuckets.cmi : bs_internalBucketsType.cmi
bs_HashMap.cmi : bs_Hash.cmi bs_Bag.cmj
bs_HashMultiMap.cmi : bs_Hash.cmi bs_Bag.cmj
bs_HashSet.cmi : bs_Hash.cmi bs_Bag.cmj
Expand All @@ -102,7 +104,6 @@ bs_Cmp.cmi :
bs_Map.cmi : bs_Cmp.cmi bs_Bag.cmj
bs_MapString.cmi :
bs_MapInt.cmi :
bs_internalSet.cmi :
bs_Set.cmi : bs_Cmp.cmi bs_Bag.cmj
bs_SetM.cmi : bs_Cmp.cmi
bs_SetInt.cmi :
Expand Down
37 changes: 37 additions & 0 deletions jscomp/others/Design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@




hierachy

# set
## bs_internalAVLset (basic module with rotation)

methods in this moudle could be shared by (at least 2 of them)

fuctional set, functional specialized set
mutable set, mutable specialized set.

for example, [mem0] could be shared by functional/mutable poly set


## bs_Set
functional poly set (depends on bs_internalAVLset)

## intenral_set.cppo.ml
## bs_intenralSetInt
## bs_internalSetString

methods could be shared by funcitional/imperative specialized set.
This intermediate module is created since we want to share methods
like [findOpt], [cmp]

## set.cppo.ml
## bs_SetInt
## bs_SetString



## setm.cpp.ml
## bs_SetIntM
## bs_SetStringM
2 changes: 1 addition & 1 deletion jscomp/others/bs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

(** Placeholder for BuckleScript data structures *)


(**/*)
(**/*)
Expand Down
5 changes: 3 additions & 2 deletions jscomp/others/bs_HashMap.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
module N = Bs_internalBuckets
module C = Bs_internalBucketsType
module B = Bs_Bag
module A = Bs_Array
type ('a, 'b,'id) t0 = ('a,'b) N.t0


Expand Down Expand Up @@ -47,8 +48,8 @@ let resize ~hash h =
let osize = Array.length odata in
let nsize = osize * 2 in
if nsize >= osize then begin (* no overflow *)
let h_buckets = C.makeSize nsize in
let ndata_tail = C.makeSize nsize in (* keep track of tail *)
let h_buckets = A.makeUninitialized nsize in
let ndata_tail = A.makeUninitialized 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)
Expand Down
5 changes: 3 additions & 2 deletions jscomp/others/bs_HashMapInt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ let hash (s : key) =
(** Adapted by Authors of BuckleScript 2017 *)
module N = Bs_internalBuckets
module C = Bs_internalBucketsType
module A = Bs_Array
type ('a, 'b,'id) t0 = ('a,'b) N.t0

type 'b t = (key,'b,unit) t0
Expand All @@ -48,8 +49,8 @@ let resize h =
let osize = Array.length odata in
let nsize = osize * 2 in
if nsize >= osize then begin (* no overflow *)
let h_buckets = C.makeSize nsize in
let ndata_tail = C.makeSize nsize in (* keep track of tail *)
let h_buckets = A.makeUninitialized nsize in
let ndata_tail = A.makeUninitialized 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 ~h_buckets ~ndata_tail h (Bs_Array.unsafe_get odata i)
Expand Down
5 changes: 3 additions & 2 deletions jscomp/others/bs_HashMapString.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ let hash (s : key) =
(** Adapted by Authors of BuckleScript 2017 *)
module N = Bs_internalBuckets
module C = Bs_internalBucketsType
module A = Bs_Array
type ('a, 'b,'id) t0 = ('a,'b) N.t0

type 'b t = (key,'b,unit) t0
Expand All @@ -48,8 +49,8 @@ let resize h =
let osize = Array.length odata in
let nsize = osize * 2 in
if nsize >= osize then begin (* no overflow *)
let h_buckets = C.makeSize nsize in
let ndata_tail = C.makeSize nsize in (* keep track of tail *)
let h_buckets = A.makeUninitialized nsize in
let ndata_tail = A.makeUninitialized 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 ~h_buckets ~ndata_tail h (Bs_Array.unsafe_get odata i)
Expand Down
5 changes: 3 additions & 2 deletions jscomp/others/bs_HashMultiMap.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
module N = Bs_internalBuckets
module C = Bs_internalBucketsType
module B = Bs_Bag
module A = Bs_Array
type ('a, 'b,'id) t0 = ('a,'b) N.t0

type ('a,'b) bucket = ('a,'b) N.bucket
Expand Down Expand Up @@ -46,8 +47,8 @@ let resize ~hash h =
let osize = Array.length odata in
let nsize = osize * 2 in
if nsize >= osize then begin (* no overflow *)
let h_buckets = C.makeSize nsize in
let ndata_tail = C.makeSize nsize in (* keep track of tail *)
let h_buckets = A.makeUninitialized nsize in
let ndata_tail = A.makeUninitialized 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)
Expand Down
6 changes: 4 additions & 2 deletions jscomp/others/bs_HashSet.ml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
module N = Bs_internalSetBuckets
module C = Bs_internalBucketsType
module B = Bs_Bag
module A = Bs_Array

type ('a,'id) t0 = 'a N.t0


Expand Down Expand Up @@ -58,8 +60,8 @@ let resize ~hash h =
let osize = Array.length odata in
let nsize = osize * 2 in
if nsize >= osize then begin (* no overflow *)
let h_buckets = C.makeSize nsize in
let ndata_tail = C.makeSize nsize in (* keep track of tail *)
let h_buckets = A.makeUninitialized nsize in
let ndata_tail = A.makeUninitialized 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)
Expand Down
5 changes: 3 additions & 2 deletions jscomp/others/bs_HashSetInt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ let hash (s : key) =
# 19
module N = Bs_internalSetBuckets
module C = Bs_internalBucketsType
module A = Bs_Array
type t = key N.t0

let rec insert_bucket ~h_buckets ~ndata_tail h old_bucket =
Expand All @@ -32,8 +33,8 @@ let resize h =
let osize = Array.length odata in
let nsize = osize * 2 in
if nsize >= osize then begin (* no overflow *)
let h_buckets = C.makeSize nsize in
let ndata_tail = C.makeSize nsize in (* keep track of tail *)
let h_buckets = A.makeUninitialized nsize in
let ndata_tail = A.makeUninitialized 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 ~h_buckets ~ndata_tail h (Bs_Array.unsafe_get odata i)
Expand Down
5 changes: 3 additions & 2 deletions jscomp/others/bs_HashSetString.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ let hash (s : key) =
# 19
module N = Bs_internalSetBuckets
module C = Bs_internalBucketsType
module A = Bs_Array
type t = key N.t0

let rec insert_bucket ~h_buckets ~ndata_tail h old_bucket =
Expand All @@ -32,8 +33,8 @@ let resize h =
let osize = Array.length odata in
let nsize = osize * 2 in
if nsize >= osize then begin (* no overflow *)
let h_buckets = C.makeSize nsize in
let ndata_tail = C.makeSize nsize in (* keep track of tail *)
let h_buckets = A.makeUninitialized nsize in
let ndata_tail = A.makeUninitialized 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 ~h_buckets ~ndata_tail h (Bs_Array.unsafe_get odata i)
Expand Down
7 changes: 4 additions & 3 deletions jscomp/others/bs_internalAVLset.mli
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ and 'elt node = private {
mutable left : 'elt t0;
key : 'elt ;
mutable right : 'elt t0;
h : int
h : int
} [@@bs.deriving abstract]
(* TODO: node is used in [subset] *)
external toOpt : 'a Js.null -> 'a option = "#null_to_opt"
Expand All @@ -30,7 +30,8 @@ val maxOpt0 : 'a t0 -> 'a option
val maxNull0 : 'a t0 -> 'a Js.null

val removeMinAuxWithRef : 'a node -> 'a ref -> 'a t0
(* [removeMinAuxWithRef n cell] return a new node with minimum removed and stored in cell *)
(* [removeMinAuxWithRef n cell] return a new node with
minimum removed and stored in cell *)
val empty0 : 'a t0
val isEmpty0 : 'a t0 -> bool
val stackAllLeft : 'a t0 -> 'a node list -> 'a node list
Expand Down Expand Up @@ -74,4 +75,4 @@ val balMutate : 'a node -> 'a node
val removeMinAuxWithRootMutate : 'a node -> 'a node -> 'a t0
(* [rmeoveMinAuxMutateWithRoot root n]
remove the minimum of n in place and store its value in the [key root]
*)
*)
24 changes: 24 additions & 0 deletions jscomp/others/bs_internalAVLtree.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
(* Copyright (C) 2018 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 ('key, 'a) t0 = ('key, 'a) node Js.null
Expand Down
12 changes: 6 additions & 6 deletions jscomp/others/bs_internalBucketsType.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type 'c container =
mutable buckets: 'c opt array; (* the buckets *)
initialSize: int; (* initial array size *)
} [@@bs.deriving abstract]
module A = Bs_Array

external makeSize : int -> 'a opt array = "Array" [@@bs.new]
external toOpt : 'a opt -> 'a option = "#undefined_to_opt"
external return : 'a -> 'a opt = "%identity"
let emptyOpt = Js.undefined
Expand All @@ -41,24 +41,24 @@ let rec power_2_above x n =
let create0 initialSize =
let s = power_2_above 16 initialSize in
container ~initialSize:s ~size:0
~buckets:(makeSize s)
~buckets:(A.makeUninitialized s)

let clear0 h =
sizeSet h 0;
let h_buckets = buckets h in
let len = Bs_Array.length h_buckets in
let len = A.length h_buckets in
for i = 0 to len - 1 do
Bs_Array.unsafe_set h_buckets i emptyOpt
A.unsafe_set h_buckets i emptyOpt
done

let reset0 h =
let len = Bs_Array.length (buckets h) in
let len = A.length (buckets h) in
let h_initialSize = initialSize h in
if len = h_initialSize then
clear0 h
else begin
sizeSet h 0;
bucketsSet h (makeSize h_initialSize)
bucketsSet h (A.makeUninitialized h_initialSize)
end

let length0 h = size h
Expand Down
46 changes: 46 additions & 0 deletions jscomp/others/bs_internalBucketsType.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
(* Copyright (C) 2018 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 'a opt = 'a Js.undefined
type 'c container =
private {
mutable size: int; (* number of entries *)
mutable buckets: 'c opt array; (* the buckets *)

} [@@bs.deriving abstract]

external toOpt : 'a opt -> 'a option = "#undefined_to_opt"
external return : 'a -> 'a opt = "%identity"

val emptyOpt : 'a Js.undefined
val create0 : int -> 'a container
val clear0 : 'a container -> unit
val reset0 : 'a container -> unit
val length0 : 'a container -> int
type statistics = {
num_bindings : int;
num_buckets : int;
max_bucket_length : int;
bucket_histogram : int array;
}
40 changes: 40 additions & 0 deletions jscomp/others/bs_internalSetBuckets.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
(* Copyright (C) 2018 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. *)

module C = Bs_internalBucketsType

type 'a bucket = {
mutable key : 'a;
mutable next : 'a bucket C.opt
}
and 'a t0 = 'a bucket C.container
[@@bs.deriving abstract]


val iter0 : 'a bucket C.container -> ('a -> 'b [@bs]) -> unit
val fillArray : int -> 'a array -> 'a bucket -> int
val toArray0 : 'a bucket C.container -> 'a array

val fold0 : 'a bucket C.container -> 'b -> ('a -> 'b -> 'b [@bs]) -> 'b
val logStats0 : 'a bucket C.container -> unit
Loading

0 comments on commit bd01da6

Please sign in to comment.