From 60faf06c1331201cb9606a7e3afcda9c9c638834 Mon Sep 17 00:00:00 2001 From: Hongbo Zhang Date: Fri, 12 Jan 2018 18:47:11 +0800 Subject: [PATCH 1/3] wip: clean up with a disign note --- jscomp/others/.depend | 9 ++--- jscomp/others/Design.md | 37 +++++++++++++++++++ jscomp/others/bs.ml | 2 +- jscomp/others/bs_HashMap.ml | 5 +-- jscomp/others/bs_HashMapInt.ml | 5 +-- jscomp/others/bs_HashMapString.ml | 5 +-- jscomp/others/bs_HashMultiMap.ml | 5 +-- jscomp/others/bs_HashSet.ml | 6 ++-- jscomp/others/bs_HashSetInt.ml | 5 +-- jscomp/others/bs_HashSetString.ml | 5 +-- jscomp/others/bs_internalAVLset.mli | 7 ++-- jscomp/others/bs_internalAVLtree.mli | 24 +++++++++++++ jscomp/others/bs_internalBucketsType.ml | 12 +++---- jscomp/others/bs_internalBucketsType.mli | 46 ++++++++++++++++++++++++ jscomp/others/bs_internalSetBuckets.mli | 40 +++++++++++++++++++++ jscomp/others/hashmap.cppo.ml | 5 +-- jscomp/others/hashset.cppo.ml | 5 +-- lib/js/bs_internalBucketsType.js | 1 - lib/js/bs_internalSetBuckets.js | 3 -- 19 files changed, 191 insertions(+), 36 deletions(-) create mode 100644 jscomp/others/Design.md create mode 100644 jscomp/others/bs_internalBucketsType.mli create mode 100644 jscomp/others/bs_internalSetBuckets.mli diff --git a/jscomp/others/.depend b/jscomp/others/.depend index 5dfcc453a27..b8115062dd6 100644 --- a/jscomp/others/.depend +++ b/jscomp/others/.depend @@ -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 @@ -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 \ @@ -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 @@ -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 : diff --git a/jscomp/others/Design.md b/jscomp/others/Design.md new file mode 100644 index 00000000000..feac754b02b --- /dev/null +++ b/jscomp/others/Design.md @@ -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 diff --git a/jscomp/others/bs.ml b/jscomp/others/bs.ml index b58c8225f81..011f1e96824 100644 --- a/jscomp/others/bs.ml +++ b/jscomp/others/bs.ml @@ -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 *) + (**/*) (**/*) diff --git a/jscomp/others/bs_HashMap.ml b/jscomp/others/bs_HashMap.ml index 8baf64b0765..c751c340950 100644 --- a/jscomp/others/bs_HashMap.ml +++ b/jscomp/others/bs_HashMap.ml @@ -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 @@ -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) diff --git a/jscomp/others/bs_HashMapInt.ml b/jscomp/others/bs_HashMapInt.ml index d4a2cf66b6b..c913798d295 100644 --- a/jscomp/others/bs_HashMapInt.ml +++ b/jscomp/others/bs_HashMapInt.ml @@ -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 @@ -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) diff --git a/jscomp/others/bs_HashMapString.ml b/jscomp/others/bs_HashMapString.ml index f4329bd50b6..b80544696c2 100644 --- a/jscomp/others/bs_HashMapString.ml +++ b/jscomp/others/bs_HashMapString.ml @@ -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 @@ -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) diff --git a/jscomp/others/bs_HashMultiMap.ml b/jscomp/others/bs_HashMultiMap.ml index 392325290fa..2603a91df98 100644 --- a/jscomp/others/bs_HashMultiMap.ml +++ b/jscomp/others/bs_HashMultiMap.ml @@ -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 @@ -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) diff --git a/jscomp/others/bs_HashSet.ml b/jscomp/others/bs_HashSet.ml index cd97af93439..ed8808eb254 100644 --- a/jscomp/others/bs_HashSet.ml +++ b/jscomp/others/bs_HashSet.ml @@ -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 @@ -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) diff --git a/jscomp/others/bs_HashSetInt.ml b/jscomp/others/bs_HashSetInt.ml index 41c9727c11e..21be6724b64 100644 --- a/jscomp/others/bs_HashSetInt.ml +++ b/jscomp/others/bs_HashSetInt.ml @@ -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 = @@ -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) diff --git a/jscomp/others/bs_HashSetString.ml b/jscomp/others/bs_HashSetString.ml index 3a71ce18606..d01e452bd93 100644 --- a/jscomp/others/bs_HashSetString.ml +++ b/jscomp/others/bs_HashSetString.ml @@ -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 = @@ -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) diff --git a/jscomp/others/bs_internalAVLset.mli b/jscomp/others/bs_internalAVLset.mli index 3dd7dc5a216..6c7940ec4d2 100644 --- a/jscomp/others/bs_internalAVLset.mli +++ b/jscomp/others/bs_internalAVLset.mli @@ -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" @@ -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 @@ -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] - *) \ No newline at end of file + *) diff --git a/jscomp/others/bs_internalAVLtree.mli b/jscomp/others/bs_internalAVLtree.mli index 0cf33b3fe8a..eb38c6d2ae8 100644 --- a/jscomp/others/bs_internalAVLtree.mli +++ b/jscomp/others/bs_internalAVLtree.mli @@ -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 diff --git a/jscomp/others/bs_internalBucketsType.ml b/jscomp/others/bs_internalBucketsType.ml index 83350700b53..47c12cd89a8 100644 --- a/jscomp/others/bs_internalBucketsType.ml +++ b/jscomp/others/bs_internalBucketsType.ml @@ -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 @@ -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 diff --git a/jscomp/others/bs_internalBucketsType.mli b/jscomp/others/bs_internalBucketsType.mli new file mode 100644 index 00000000000..13897093249 --- /dev/null +++ b/jscomp/others/bs_internalBucketsType.mli @@ -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; +} diff --git a/jscomp/others/bs_internalSetBuckets.mli b/jscomp/others/bs_internalSetBuckets.mli new file mode 100644 index 00000000000..5d8114eb920 --- /dev/null +++ b/jscomp/others/bs_internalSetBuckets.mli @@ -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 diff --git a/jscomp/others/hashmap.cppo.ml b/jscomp/others/hashmap.cppo.ml index 10329bcda2b..ac62b5b383d 100644 --- a/jscomp/others/hashmap.cppo.ml +++ b/jscomp/others/hashmap.cppo.ml @@ -31,6 +31,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 @@ -57,8 +58,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) diff --git a/jscomp/others/hashset.cppo.ml b/jscomp/others/hashset.cppo.ml index a22ffcb2abe..094fe4be282 100644 --- a/jscomp/others/hashset.cppo.ml +++ b/jscomp/others/hashset.cppo.ml @@ -18,6 +18,7 @@ let hash (s : key) = 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 = @@ -41,8 +42,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) diff --git a/lib/js/bs_internalBucketsType.js b/lib/js/bs_internalBucketsType.js index e5f569222af..8409fe0d15e 100644 --- a/lib/js/bs_internalBucketsType.js +++ b/lib/js/bs_internalBucketsType.js @@ -54,7 +54,6 @@ function length0(h) { } exports.emptyOpt = emptyOpt; -exports.power_2_above = power_2_above; exports.create0 = create0; exports.clear0 = clear0; exports.reset0 = reset0; diff --git a/lib/js/bs_internalSetBuckets.js b/lib/js/bs_internalSetBuckets.js index 563cbdfe52c..70914793529 100644 --- a/lib/js/bs_internalSetBuckets.js +++ b/lib/js/bs_internalSetBuckets.js @@ -123,12 +123,9 @@ function logStats0(h) { var C = 0; exports.C = C; -exports.bucket_length = bucket_length; -exports.do_bucket_iter = do_bucket_iter; exports.iter0 = iter0; exports.fillArray = fillArray; exports.toArray0 = toArray0; -exports.do_bucket_fold = do_bucket_fold; exports.fold0 = fold0; exports.logStats0 = logStats0; /* No side effect */ From 927d48047b65a0d19aceb9af5fa7bf71af64e55b Mon Sep 17 00:00:00 2001 From: Hongbo Zhang Date: Fri, 12 Jan 2018 20:50:14 +0800 Subject: [PATCH 2/3] clean up --- jscomp/others/Design.md | 2 + jscomp/others/bs_SetInt.ml | 102 +++++++++++++- jscomp/others/bs_SetString.ml | 102 +++++++++++++- jscomp/others/bs_internalAVLtree.mli | 1 + jscomp/others/bs_internalBucketsType.ml | 10 +- jscomp/others/bs_internalSetBuckets.ml | 20 +-- jscomp/others/bs_internalSetInt.ml | 95 ------------- jscomp/others/bs_internalSetString.ml | 95 ------------- jscomp/others/internal_set.cppo.ml | 95 ------------- jscomp/others/set.cppo.ml | 102 +++++++++++++- lib/js/bs_SetInt.js | 178 ++++++++++++++++++++++-- lib/js/bs_SetString.js | 178 ++++++++++++++++++++++-- lib/js/bs_internalSetBuckets.js | 14 +- lib/js/bs_internalSetInt.js | 176 ----------------------- lib/js/bs_internalSetString.js | 176 ----------------------- 15 files changed, 656 insertions(+), 690 deletions(-) diff --git a/jscomp/others/Design.md b/jscomp/others/Design.md index feac754b02b..763f635f4ca 100644 --- a/jscomp/others/Design.md +++ b/jscomp/others/Design.md @@ -35,3 +35,5 @@ hierachy ## setm.cpp.ml ## bs_SetIntM ## bs_SetStringM + +# map \ No newline at end of file diff --git a/jscomp/others/bs_SetInt.ml b/jscomp/others/bs_SetInt.ml index 5308717de57..9064d88bc5f 100644 --- a/jscomp/others/bs_SetInt.ml +++ b/jscomp/others/bs_SetInt.ml @@ -30,13 +30,107 @@ let checkInvariant = N.checkInvariant let add = I.add let ofArray = I.ofArray let cmp = I.cmp -let diff = I.diff let eq = I.eq let findOpt = I.findOpt -let split = I.split let subset = I.subset -let inter = I.inter -let union = I.union let remove = I.remove let mem = I.mem +let rec splitAuxNoPivot (n : _ N.node) (x : elt) : t * t = + let l,v,r = N.(left n , key n, right n) in + if x = v then l, r + else if x < v then + match N.toOpt l with + | None -> + N.empty , N.return n + | Some l -> + let ll, rl = splitAuxNoPivot l x in + ll, N.joinShared rl v r + else + match N.toOpt r with + | None -> + N.return n, N.empty + | Some r -> + let lr, rr = splitAuxNoPivot r x in + N.joinShared l v lr, rr + + +let rec splitAuxPivot (n : _ N.node) (x : elt) pres : t * t = + let l,v,r = N.(left n , key n, right n) in + if x = v then begin + pres := true; + (l, r) + end + else if x < v then + match N.toOpt l with + | None -> + N.empty, N.return n + | Some l -> + let ll, rl = splitAuxPivot l x pres in + ll, N.joinShared rl v r + else + match N.toOpt r with + | None -> + N.return n, N.empty + | Some r -> + let lr, rr = splitAuxPivot r x pres in + N.joinShared l v lr, rr + + +let split (t : t) (x : elt) = + match N.toOpt t with + None -> + (N.empty, N.empty), false + | Some n -> + let pres = ref false in + let v = splitAuxPivot n x pres in + v, !pres + +let rec union (s1 : t) (s2 : t) = + match N.(toOpt s1, toOpt s2) with + (None, _) -> s2 + | (_, None) -> s1 + | Some n1, Some n2 (* (Node(l1, v1, r1, h1), Node(l2, v2, r2, h2)) *) -> + let h1, h2 = N.(h n1 , h n2) in + if h1 >= h2 then + if h2 = 1 then I.add s1 (N.key n2) else begin + let l1, v1, r1 = N.(left n1, key n1, right n1) in + let (l2, r2) = splitAuxNoPivot n2 v1 in + N.joinShared (union l1 l2) v1 (union r1 r2) + end + else + if h1 = 1 then add s2 (N.key n1) else begin + let l2, v2, r2 = N.(left n2 , key n2, right n2) in + let (l1, r1) = splitAuxNoPivot n1 v2 in + N.joinShared (union l1 l2) v2 (union r1 r2) + end + +let rec inter (s1 : t) (s2 : t) = + match N.(toOpt s1, toOpt s2) with + (None, _) + | (_, None) -> N.empty + | Some n1, Some n2 (* (Node(l1, v1, r1, _), t2) *) -> + let l1,v1,r1 = N.(left n1, key n1, right n1) in + let pres = ref false in + let l2,r2 = splitAuxPivot n2 v1 pres in + let ll = inter l1 l2 in + let rr = inter r1 r2 in + if !pres then N.joinShared ll v1 rr + else N.concatShared ll rr + +let rec diff (s1 : t) (s2 : t) = + match N.(toOpt s1, toOpt s2) with + | (None, _) + | (_, None) -> s1 + | Some n1, Some n2 (* (Node(l1, v1, r1, _), t2) *) -> + let l1,v1,r1 = N.(left n1, key n1, right n1) in + let pres = ref false in + let l2, r2 = splitAuxPivot n2 v1 pres in + let ll = diff l1 l2 in + let rr = diff r1 r2 in + if !pres then N.concatShared ll rr + else N.joinShared ll v1 rr + + + + diff --git a/jscomp/others/bs_SetString.ml b/jscomp/others/bs_SetString.ml index e5bacd20fb6..0d7766d981f 100644 --- a/jscomp/others/bs_SetString.ml +++ b/jscomp/others/bs_SetString.ml @@ -30,13 +30,107 @@ let checkInvariant = N.checkInvariant let add = I.add let ofArray = I.ofArray let cmp = I.cmp -let diff = I.diff let eq = I.eq let findOpt = I.findOpt -let split = I.split let subset = I.subset -let inter = I.inter -let union = I.union let remove = I.remove let mem = I.mem +let rec splitAuxNoPivot (n : _ N.node) (x : elt) : t * t = + let l,v,r = N.(left n , key n, right n) in + if x = v then l, r + else if x < v then + match N.toOpt l with + | None -> + N.empty , N.return n + | Some l -> + let ll, rl = splitAuxNoPivot l x in + ll, N.joinShared rl v r + else + match N.toOpt r with + | None -> + N.return n, N.empty + | Some r -> + let lr, rr = splitAuxNoPivot r x in + N.joinShared l v lr, rr + + +let rec splitAuxPivot (n : _ N.node) (x : elt) pres : t * t = + let l,v,r = N.(left n , key n, right n) in + if x = v then begin + pres := true; + (l, r) + end + else if x < v then + match N.toOpt l with + | None -> + N.empty, N.return n + | Some l -> + let ll, rl = splitAuxPivot l x pres in + ll, N.joinShared rl v r + else + match N.toOpt r with + | None -> + N.return n, N.empty + | Some r -> + let lr, rr = splitAuxPivot r x pres in + N.joinShared l v lr, rr + + +let split (t : t) (x : elt) = + match N.toOpt t with + None -> + (N.empty, N.empty), false + | Some n -> + let pres = ref false in + let v = splitAuxPivot n x pres in + v, !pres + +let rec union (s1 : t) (s2 : t) = + match N.(toOpt s1, toOpt s2) with + (None, _) -> s2 + | (_, None) -> s1 + | Some n1, Some n2 (* (Node(l1, v1, r1, h1), Node(l2, v2, r2, h2)) *) -> + let h1, h2 = N.(h n1 , h n2) in + if h1 >= h2 then + if h2 = 1 then I.add s1 (N.key n2) else begin + let l1, v1, r1 = N.(left n1, key n1, right n1) in + let (l2, r2) = splitAuxNoPivot n2 v1 in + N.joinShared (union l1 l2) v1 (union r1 r2) + end + else + if h1 = 1 then add s2 (N.key n1) else begin + let l2, v2, r2 = N.(left n2 , key n2, right n2) in + let (l1, r1) = splitAuxNoPivot n1 v2 in + N.joinShared (union l1 l2) v2 (union r1 r2) + end + +let rec inter (s1 : t) (s2 : t) = + match N.(toOpt s1, toOpt s2) with + (None, _) + | (_, None) -> N.empty + | Some n1, Some n2 (* (Node(l1, v1, r1, _), t2) *) -> + let l1,v1,r1 = N.(left n1, key n1, right n1) in + let pres = ref false in + let l2,r2 = splitAuxPivot n2 v1 pres in + let ll = inter l1 l2 in + let rr = inter r1 r2 in + if !pres then N.joinShared ll v1 rr + else N.concatShared ll rr + +let rec diff (s1 : t) (s2 : t) = + match N.(toOpt s1, toOpt s2) with + | (None, _) + | (_, None) -> s1 + | Some n1, Some n2 (* (Node(l1, v1, r1, _), t2) *) -> + let l1,v1,r1 = N.(left n1, key n1, right n1) in + let pres = ref false in + let l2, r2 = splitAuxPivot n2 v1 pres in + let ll = diff l1 l2 in + let rr = diff r1 r2 in + if !pres then N.concatShared ll rr + else N.joinShared ll v1 rr + + + + diff --git a/jscomp/others/bs_internalAVLtree.mli b/jscomp/others/bs_internalAVLtree.mli index eb38c6d2ae8..5ec85a23be2 100644 --- a/jscomp/others/bs_internalAVLtree.mli +++ b/jscomp/others/bs_internalAVLtree.mli @@ -25,6 +25,7 @@ type ('key, 'a) t0 = ('key, 'a) node Js.null + and ('k, + 'v) node = { left : ('k,'v) t0; key : 'k; diff --git a/jscomp/others/bs_internalBucketsType.ml b/jscomp/others/bs_internalBucketsType.ml index 47c12cd89a8..f9e3712b8e7 100644 --- a/jscomp/others/bs_internalBucketsType.ml +++ b/jscomp/others/bs_internalBucketsType.ml @@ -64,14 +64,8 @@ let reset0 h = let length0 h = size h -type statistics = { - num_bindings: int; - num_buckets: int; - max_bucket_length: int; - bucket_histogram: int array -} -(* + type statistics = { num_bindings: int; (** Number of bindings present in the table. @@ -84,4 +78,4 @@ type statistics = { (** Histogram of bucket sizes. This array [histo] has length [max_bucket_length + 1]. The value of [histo.(i)] is the number of buckets whose size is [i]. *) -} *) \ No newline at end of file +} \ No newline at end of file diff --git a/jscomp/others/bs_internalSetBuckets.ml b/jscomp/others/bs_internalSetBuckets.ml index 61b7ff3d5cf..ebb2d72bce6 100644 --- a/jscomp/others/bs_internalSetBuckets.ml +++ b/jscomp/others/bs_internalSetBuckets.ml @@ -38,24 +38,24 @@ type 'a bucket = { and 'a t0 = 'a bucket C.container [@@bs.deriving abstract] -let rec bucket_length accu buckets = +let rec bucketLength accu buckets = match C.toOpt buckets with | None -> accu - | Some cell -> bucket_length (accu + 1) (next cell) + | Some cell -> bucketLength (accu + 1) (next cell) -let rec do_bucket_iter ~f buckets = +let rec doBucketIter ~f buckets = match C.toOpt buckets with | None -> () | Some cell -> - f (key cell) [@bs]; do_bucket_iter ~f (next cell) + f (key cell) [@bs]; doBucketIter ~f (next cell) let iter0 h f = let d = C.buckets h in for i = 0 to Bs_Array.length d - 1 do - do_bucket_iter f (Bs_Array.unsafe_get d i) + doBucketIter f (Bs_Array.unsafe_get d i) done let rec fillArray i arr cell = @@ -79,18 +79,18 @@ let toArray0 h = -let rec do_bucket_fold ~f b accu = +let rec doBucketFold ~f b accu = match C.toOpt b with | None -> accu | Some cell -> - do_bucket_fold ~f (next cell) (f (key cell) accu [@bs]) + doBucketFold ~f (next cell) (f (key cell) accu [@bs]) let fold0 h init f = let d = C.buckets h in let accu = ref init in for i = 0 to Bs_Array.length d - 1 do - accu := do_bucket_fold ~f (Bs_Array.unsafe_get d i) !accu + accu := doBucketFold ~f (Bs_Array.unsafe_get d i) !accu done; !accu @@ -100,12 +100,12 @@ let fold0 h init f = let logStats0 h = let mbl = Bs_Array.foldLeft (C.buckets h) 0 (fun[@bs] m b -> - let len = (bucket_length 0 b) in + let len = (bucketLength 0 b) in max m len) in let histo = Bs_Array.init (mbl + 1) (fun[@bs] _ -> 0) in Bs_Array.iter (C.buckets h) (fun[@bs] b -> - let l = bucket_length 0 b in + let l = bucketLength 0 b in Bs_Array.unsafe_set histo l (Bs_Array.unsafe_get histo l + 1) ) ; diff --git a/jscomp/others/bs_internalSetInt.ml b/jscomp/others/bs_internalSetInt.ml index a9587e22545..15a000e5e9b 100644 --- a/jscomp/others/bs_internalSetInt.ml +++ b/jscomp/others/bs_internalSetInt.ml @@ -81,101 +81,6 @@ let eq (s1 : t) s2 = cmp s1 s2 = 0 -let rec splitAuxNoPivot (n : _ N.node) (x : elt) : t * t = - let l,v,r = N.(left n , key n, right n) in - if x = v then l, r - else if x < v then - match N.toOpt l with - | None -> - N.empty , N.return n - | Some l -> - let ll, rl = splitAuxNoPivot l x in - ll, N.joinShared rl v r - else - match N.toOpt r with - | None -> - N.return n, N.empty - | Some r -> - let lr, rr = splitAuxNoPivot r x in - N.joinShared l v lr, rr - - -let rec splitAuxPivot (n : _ N.node) (x : elt) pres : t * t = - let l,v,r = N.(left n , key n, right n) in - if x = v then begin - pres := true; - (l, r) - end - else if x < v then - match N.toOpt l with - | None -> - N.empty, N.return n - | Some l -> - let ll, rl = splitAuxPivot l x pres in - ll, N.joinShared rl v r - else - match N.toOpt r with - | None -> - N.return n, N.empty - | Some r -> - let lr, rr = splitAuxPivot r x pres in - N.joinShared l v lr, rr - - -let split (t : t) (x : elt) = - match N.toOpt t with - None -> - (N.empty, N.empty), false - | Some n -> - let pres = ref false in - let v = splitAuxPivot n x pres in - v, !pres - - -let rec union (s1 : t) (s2 : t) = - match N.(toOpt s1, toOpt s2) with - (None, _) -> s2 - | (_, None) -> s1 - | Some n1, Some n2 (* (Node(l1, v1, r1, h1), Node(l2, v2, r2, h2)) *) -> - let h1, h2 = N.(h n1 , h n2) in - if h1 >= h2 then - if h2 = 1 then add s1 (N.key n2) else begin - let l1, v1, r1 = N.(left n1, key n1, right n1) in - let (l2, r2) = splitAuxNoPivot n2 v1 in - N.joinShared (union l1 l2) v1 (union r1 r2) - end - else - if h1 = 1 then add s2 (N.key n1) else begin - let l2, v2, r2 = N.(left n2 , key n2, right n2) in - let (l1, r1) = splitAuxNoPivot n1 v2 in - N.joinShared (union l1 l2) v2 (union r1 r2) - end - -let rec inter (s1 : t) (s2 : t) = - match N.(toOpt s1, toOpt s2) with - (None, _) - | (_, None) -> N.empty - | Some n1, Some n2 (* (Node(l1, v1, r1, _), t2) *) -> - let l1,v1,r1 = N.(left n1, key n1, right n1) in - let pres = ref false in - let l2,r2 = splitAuxPivot n2 v1 pres in - let ll = inter l1 l2 in - let rr = inter r1 r2 in - if !pres then N.joinShared ll v1 rr - else N.concatShared ll rr - -let rec diff (s1 : t) (s2 : t) = - match N.(toOpt s1, toOpt s2) with - | (None, _) - | (_, None) -> s1 - | Some n1, Some n2 (* (Node(l1, v1, r1, _), t2) *) -> - let l1,v1,r1 = N.(left n1, key n1, right n1) in - let pres = ref false in - let l2, r2 = splitAuxPivot n2 v1 pres in - let ll = diff l1 l2 in - let rr = diff r1 r2 in - if !pres then N.concatShared ll rr - else N.joinShared ll v1 rr diff --git a/jscomp/others/bs_internalSetString.ml b/jscomp/others/bs_internalSetString.ml index 83422b35cf1..1eae5a4c91c 100644 --- a/jscomp/others/bs_internalSetString.ml +++ b/jscomp/others/bs_internalSetString.ml @@ -81,101 +81,6 @@ let eq (s1 : t) s2 = cmp s1 s2 = 0 -let rec splitAuxNoPivot (n : _ N.node) (x : elt) : t * t = - let l,v,r = N.(left n , key n, right n) in - if x = v then l, r - else if x < v then - match N.toOpt l with - | None -> - N.empty , N.return n - | Some l -> - let ll, rl = splitAuxNoPivot l x in - ll, N.joinShared rl v r - else - match N.toOpt r with - | None -> - N.return n, N.empty - | Some r -> - let lr, rr = splitAuxNoPivot r x in - N.joinShared l v lr, rr - - -let rec splitAuxPivot (n : _ N.node) (x : elt) pres : t * t = - let l,v,r = N.(left n , key n, right n) in - if x = v then begin - pres := true; - (l, r) - end - else if x < v then - match N.toOpt l with - | None -> - N.empty, N.return n - | Some l -> - let ll, rl = splitAuxPivot l x pres in - ll, N.joinShared rl v r - else - match N.toOpt r with - | None -> - N.return n, N.empty - | Some r -> - let lr, rr = splitAuxPivot r x pres in - N.joinShared l v lr, rr - - -let split (t : t) (x : elt) = - match N.toOpt t with - None -> - (N.empty, N.empty), false - | Some n -> - let pres = ref false in - let v = splitAuxPivot n x pres in - v, !pres - - -let rec union (s1 : t) (s2 : t) = - match N.(toOpt s1, toOpt s2) with - (None, _) -> s2 - | (_, None) -> s1 - | Some n1, Some n2 (* (Node(l1, v1, r1, h1), Node(l2, v2, r2, h2)) *) -> - let h1, h2 = N.(h n1 , h n2) in - if h1 >= h2 then - if h2 = 1 then add s1 (N.key n2) else begin - let l1, v1, r1 = N.(left n1, key n1, right n1) in - let (l2, r2) = splitAuxNoPivot n2 v1 in - N.joinShared (union l1 l2) v1 (union r1 r2) - end - else - if h1 = 1 then add s2 (N.key n1) else begin - let l2, v2, r2 = N.(left n2 , key n2, right n2) in - let (l1, r1) = splitAuxNoPivot n1 v2 in - N.joinShared (union l1 l2) v2 (union r1 r2) - end - -let rec inter (s1 : t) (s2 : t) = - match N.(toOpt s1, toOpt s2) with - (None, _) - | (_, None) -> N.empty - | Some n1, Some n2 (* (Node(l1, v1, r1, _), t2) *) -> - let l1,v1,r1 = N.(left n1, key n1, right n1) in - let pres = ref false in - let l2,r2 = splitAuxPivot n2 v1 pres in - let ll = inter l1 l2 in - let rr = inter r1 r2 in - if !pres then N.joinShared ll v1 rr - else N.concatShared ll rr - -let rec diff (s1 : t) (s2 : t) = - match N.(toOpt s1, toOpt s2) with - | (None, _) - | (_, None) -> s1 - | Some n1, Some n2 (* (Node(l1, v1, r1, _), t2) *) -> - let l1,v1,r1 = N.(left n1, key n1, right n1) in - let pres = ref false in - let l2, r2 = splitAuxPivot n2 v1 pres in - let ll = diff l1 l2 in - let rr = diff r1 r2 in - if !pres then N.concatShared ll rr - else N.joinShared ll v1 rr diff --git a/jscomp/others/internal_set.cppo.ml b/jscomp/others/internal_set.cppo.ml index da5a85c9967..f7375d2ff57 100644 --- a/jscomp/others/internal_set.cppo.ml +++ b/jscomp/others/internal_set.cppo.ml @@ -85,101 +85,6 @@ let eq (s1 : t) s2 = cmp s1 s2 = 0 -let rec splitAuxNoPivot (n : _ N.node) (x : elt) : t * t = - let l,v,r = N.(left n , key n, right n) in - if x = v then l, r - else if x < v then - match N.toOpt l with - | None -> - N.empty , N.return n - | Some l -> - let ll, rl = splitAuxNoPivot l x in - ll, N.joinShared rl v r - else - match N.toOpt r with - | None -> - N.return n, N.empty - | Some r -> - let lr, rr = splitAuxNoPivot r x in - N.joinShared l v lr, rr - - -let rec splitAuxPivot (n : _ N.node) (x : elt) pres : t * t = - let l,v,r = N.(left n , key n, right n) in - if x = v then begin - pres := true; - (l, r) - end - else if x < v then - match N.toOpt l with - | None -> - N.empty, N.return n - | Some l -> - let ll, rl = splitAuxPivot l x pres in - ll, N.joinShared rl v r - else - match N.toOpt r with - | None -> - N.return n, N.empty - | Some r -> - let lr, rr = splitAuxPivot r x pres in - N.joinShared l v lr, rr - - -let split (t : t) (x : elt) = - match N.toOpt t with - None -> - (N.empty, N.empty), false - | Some n -> - let pres = ref false in - let v = splitAuxPivot n x pres in - v, !pres - - -let rec union (s1 : t) (s2 : t) = - match N.(toOpt s1, toOpt s2) with - (None, _) -> s2 - | (_, None) -> s1 - | Some n1, Some n2 (* (Node(l1, v1, r1, h1), Node(l2, v2, r2, h2)) *) -> - let h1, h2 = N.(h n1 , h n2) in - if h1 >= h2 then - if h2 = 1 then add s1 (N.key n2) else begin - let l1, v1, r1 = N.(left n1, key n1, right n1) in - let (l2, r2) = splitAuxNoPivot n2 v1 in - N.joinShared (union l1 l2) v1 (union r1 r2) - end - else - if h1 = 1 then add s2 (N.key n1) else begin - let l2, v2, r2 = N.(left n2 , key n2, right n2) in - let (l1, r1) = splitAuxNoPivot n1 v2 in - N.joinShared (union l1 l2) v2 (union r1 r2) - end - -let rec inter (s1 : t) (s2 : t) = - match N.(toOpt s1, toOpt s2) with - (None, _) - | (_, None) -> N.empty - | Some n1, Some n2 (* (Node(l1, v1, r1, _), t2) *) -> - let l1,v1,r1 = N.(left n1, key n1, right n1) in - let pres = ref false in - let l2,r2 = splitAuxPivot n2 v1 pres in - let ll = inter l1 l2 in - let rr = inter r1 r2 in - if !pres then N.joinShared ll v1 rr - else N.concatShared ll rr - -let rec diff (s1 : t) (s2 : t) = - match N.(toOpt s1, toOpt s2) with - | (None, _) - | (_, None) -> s1 - | Some n1, Some n2 (* (Node(l1, v1, r1, _), t2) *) -> - let l1,v1,r1 = N.(left n1, key n1, right n1) in - let pres = ref false in - let l2, r2 = splitAuxPivot n2 v1 pres in - let ll = diff l1 l2 in - let rr = diff r1 r2 in - if !pres then N.concatShared ll rr - else N.joinShared ll v1 rr diff --git a/jscomp/others/set.cppo.ml b/jscomp/others/set.cppo.ml index 44394f2eb87..c1a71412abe 100644 --- a/jscomp/others/set.cppo.ml +++ b/jscomp/others/set.cppo.ml @@ -34,13 +34,107 @@ let checkInvariant = N.checkInvariant let add = I.add let ofArray = I.ofArray let cmp = I.cmp -let diff = I.diff let eq = I.eq let findOpt = I.findOpt -let split = I.split let subset = I.subset -let inter = I.inter -let union = I.union let remove = I.remove let mem = I.mem +let rec splitAuxNoPivot (n : _ N.node) (x : elt) : t * t = + let l,v,r = N.(left n , key n, right n) in + if x = v then l, r + else if x < v then + match N.toOpt l with + | None -> + N.empty , N.return n + | Some l -> + let ll, rl = splitAuxNoPivot l x in + ll, N.joinShared rl v r + else + match N.toOpt r with + | None -> + N.return n, N.empty + | Some r -> + let lr, rr = splitAuxNoPivot r x in + N.joinShared l v lr, rr + + +let rec splitAuxPivot (n : _ N.node) (x : elt) pres : t * t = + let l,v,r = N.(left n , key n, right n) in + if x = v then begin + pres := true; + (l, r) + end + else if x < v then + match N.toOpt l with + | None -> + N.empty, N.return n + | Some l -> + let ll, rl = splitAuxPivot l x pres in + ll, N.joinShared rl v r + else + match N.toOpt r with + | None -> + N.return n, N.empty + | Some r -> + let lr, rr = splitAuxPivot r x pres in + N.joinShared l v lr, rr + + +let split (t : t) (x : elt) = + match N.toOpt t with + None -> + (N.empty, N.empty), false + | Some n -> + let pres = ref false in + let v = splitAuxPivot n x pres in + v, !pres + +let rec union (s1 : t) (s2 : t) = + match N.(toOpt s1, toOpt s2) with + (None, _) -> s2 + | (_, None) -> s1 + | Some n1, Some n2 (* (Node(l1, v1, r1, h1), Node(l2, v2, r2, h2)) *) -> + let h1, h2 = N.(h n1 , h n2) in + if h1 >= h2 then + if h2 = 1 then I.add s1 (N.key n2) else begin + let l1, v1, r1 = N.(left n1, key n1, right n1) in + let (l2, r2) = splitAuxNoPivot n2 v1 in + N.joinShared (union l1 l2) v1 (union r1 r2) + end + else + if h1 = 1 then add s2 (N.key n1) else begin + let l2, v2, r2 = N.(left n2 , key n2, right n2) in + let (l1, r1) = splitAuxNoPivot n1 v2 in + N.joinShared (union l1 l2) v2 (union r1 r2) + end + +let rec inter (s1 : t) (s2 : t) = + match N.(toOpt s1, toOpt s2) with + (None, _) + | (_, None) -> N.empty + | Some n1, Some n2 (* (Node(l1, v1, r1, _), t2) *) -> + let l1,v1,r1 = N.(left n1, key n1, right n1) in + let pres = ref false in + let l2,r2 = splitAuxPivot n2 v1 pres in + let ll = inter l1 l2 in + let rr = inter r1 r2 in + if !pres then N.joinShared ll v1 rr + else N.concatShared ll rr + +let rec diff (s1 : t) (s2 : t) = + match N.(toOpt s1, toOpt s2) with + | (None, _) + | (_, None) -> s1 + | Some n1, Some n2 (* (Node(l1, v1, r1, _), t2) *) -> + let l1,v1,r1 = N.(left n1, key n1, right n1) in + let pres = ref false in + let l2, r2 = splitAuxPivot n2 v1 pres in + let ll = diff l1 l2 in + let rr = diff r1 r2 in + if !pres then N.concatShared ll rr + else N.joinShared ll v1 rr + + + + diff --git a/lib/js/bs_SetInt.js b/lib/js/bs_SetInt.js index 950a79ae4e1..2f9cb9623ae 100644 --- a/lib/js/bs_SetInt.js +++ b/lib/js/bs_SetInt.js @@ -3,6 +3,176 @@ var Bs_internalAVLset = require("./bs_internalAVLset.js"); var Bs_internalSetInt = require("./bs_internalSetInt.js"); +function splitAuxNoPivot(n, x) { + var l = n.left; + var v = n.key; + var r = n.right; + if (x === v) { + return /* tuple */[ + l, + r + ]; + } else if (x < v) { + if (l !== null) { + var match = splitAuxNoPivot(l, x); + return /* tuple */[ + match[0], + Bs_internalAVLset.joinShared(match[1], v, r) + ]; + } else { + return /* tuple */[ + null, + n + ]; + } + } else if (r !== null) { + var match$1 = splitAuxNoPivot(r, x); + return /* tuple */[ + Bs_internalAVLset.joinShared(l, v, match$1[0]), + match$1[1] + ]; + } else { + return /* tuple */[ + n, + null + ]; + } +} + +function splitAuxPivot(n, x, pres) { + var l = n.left; + var v = n.key; + var r = n.right; + if (x === v) { + pres[0] = /* true */1; + return /* tuple */[ + l, + r + ]; + } else if (x < v) { + if (l !== null) { + var match = splitAuxPivot(l, x, pres); + return /* tuple */[ + match[0], + Bs_internalAVLset.joinShared(match[1], v, r) + ]; + } else { + return /* tuple */[ + null, + n + ]; + } + } else if (r !== null) { + var match$1 = splitAuxPivot(r, x, pres); + return /* tuple */[ + Bs_internalAVLset.joinShared(l, v, match$1[0]), + match$1[1] + ]; + } else { + return /* tuple */[ + n, + null + ]; + } +} + +function split(t, x) { + if (t !== null) { + var pres = [/* false */0]; + var v = splitAuxPivot(t, x, pres); + return /* tuple */[ + v, + pres[0] + ]; + } else { + return /* tuple */[ + /* tuple */[ + null, + null + ], + /* false */0 + ]; + } +} + +function union(s1, s2) { + if (s1 !== null) { + if (s2 !== null) { + var h1 = s1.h; + var h2 = s2.h; + if (h1 >= h2) { + if (h2 === 1) { + return Bs_internalSetInt.add(s1, s2.key); + } else { + var l1 = s1.left; + var v1 = s1.key; + var r1 = s1.right; + var match = splitAuxNoPivot(s2, v1); + return Bs_internalAVLset.joinShared(union(l1, match[0]), v1, union(r1, match[1])); + } + } else if (h1 === 1) { + return Bs_internalSetInt.add(s2, s1.key); + } else { + var l2 = s2.left; + var v2 = s2.key; + var r2 = s2.right; + var match$1 = splitAuxNoPivot(s1, v2); + return Bs_internalAVLset.joinShared(union(match$1[0], l2), v2, union(match$1[1], r2)); + } + } else { + return s1; + } + } else { + return s2; + } +} + +function inter(s1, s2) { + if (s1 !== null) { + if (s2 !== null) { + var l1 = s1.left; + var v1 = s1.key; + var r1 = s1.right; + var pres = [/* false */0]; + var match = splitAuxPivot(s2, v1, pres); + var ll = inter(l1, match[0]); + var rr = inter(r1, match[1]); + if (pres[0]) { + return Bs_internalAVLset.joinShared(ll, v1, rr); + } else { + return Bs_internalAVLset.concatShared(ll, rr); + } + } else { + return null; + } + } else { + return null; + } +} + +function diff(s1, s2) { + if (s1 !== null) { + if (s2 !== null) { + var l1 = s1.left; + var v1 = s1.key; + var r1 = s1.right; + var pres = [/* false */0]; + var match = splitAuxPivot(s2, v1, pres); + var ll = diff(l1, match[0]); + var rr = diff(r1, match[1]); + if (pres[0]) { + return Bs_internalAVLset.concatShared(ll, rr); + } else { + return Bs_internalAVLset.joinShared(ll, v1, rr); + } + } else { + return s1; + } + } else { + return s1; + } +} + var empty = Bs_internalAVLset.empty0; var isEmpty = Bs_internalAVLset.isEmpty0; @@ -15,12 +185,6 @@ var singleton = Bs_internalAVLset.singleton0; var remove = Bs_internalSetInt.remove; -var union = Bs_internalSetInt.union; - -var inter = Bs_internalSetInt.inter; - -var diff = Bs_internalSetInt.diff; - var cmp = Bs_internalSetInt.cmp; var eq = Bs_internalSetInt.eq; @@ -57,8 +221,6 @@ var maxOpt = Bs_internalAVLset.maxOpt0; var maxNull = Bs_internalAVLset.maxNull0; -var split = Bs_internalSetInt.split; - var findOpt = Bs_internalSetInt.findOpt; var checkInvariant = Bs_internalAVLset.checkInvariant; diff --git a/lib/js/bs_SetString.js b/lib/js/bs_SetString.js index c41c6400f7d..1b4609c0d6c 100644 --- a/lib/js/bs_SetString.js +++ b/lib/js/bs_SetString.js @@ -3,6 +3,176 @@ var Bs_internalAVLset = require("./bs_internalAVLset.js"); var Bs_internalSetString = require("./bs_internalSetString.js"); +function splitAuxNoPivot(n, x) { + var l = n.left; + var v = n.key; + var r = n.right; + if (x === v) { + return /* tuple */[ + l, + r + ]; + } else if (x < v) { + if (l !== null) { + var match = splitAuxNoPivot(l, x); + return /* tuple */[ + match[0], + Bs_internalAVLset.joinShared(match[1], v, r) + ]; + } else { + return /* tuple */[ + null, + n + ]; + } + } else if (r !== null) { + var match$1 = splitAuxNoPivot(r, x); + return /* tuple */[ + Bs_internalAVLset.joinShared(l, v, match$1[0]), + match$1[1] + ]; + } else { + return /* tuple */[ + n, + null + ]; + } +} + +function splitAuxPivot(n, x, pres) { + var l = n.left; + var v = n.key; + var r = n.right; + if (x === v) { + pres[0] = /* true */1; + return /* tuple */[ + l, + r + ]; + } else if (x < v) { + if (l !== null) { + var match = splitAuxPivot(l, x, pres); + return /* tuple */[ + match[0], + Bs_internalAVLset.joinShared(match[1], v, r) + ]; + } else { + return /* tuple */[ + null, + n + ]; + } + } else if (r !== null) { + var match$1 = splitAuxPivot(r, x, pres); + return /* tuple */[ + Bs_internalAVLset.joinShared(l, v, match$1[0]), + match$1[1] + ]; + } else { + return /* tuple */[ + n, + null + ]; + } +} + +function split(t, x) { + if (t !== null) { + var pres = [/* false */0]; + var v = splitAuxPivot(t, x, pres); + return /* tuple */[ + v, + pres[0] + ]; + } else { + return /* tuple */[ + /* tuple */[ + null, + null + ], + /* false */0 + ]; + } +} + +function union(s1, s2) { + if (s1 !== null) { + if (s2 !== null) { + var h1 = s1.h; + var h2 = s2.h; + if (h1 >= h2) { + if (h2 === 1) { + return Bs_internalSetString.add(s1, s2.key); + } else { + var l1 = s1.left; + var v1 = s1.key; + var r1 = s1.right; + var match = splitAuxNoPivot(s2, v1); + return Bs_internalAVLset.joinShared(union(l1, match[0]), v1, union(r1, match[1])); + } + } else if (h1 === 1) { + return Bs_internalSetString.add(s2, s1.key); + } else { + var l2 = s2.left; + var v2 = s2.key; + var r2 = s2.right; + var match$1 = splitAuxNoPivot(s1, v2); + return Bs_internalAVLset.joinShared(union(match$1[0], l2), v2, union(match$1[1], r2)); + } + } else { + return s1; + } + } else { + return s2; + } +} + +function inter(s1, s2) { + if (s1 !== null) { + if (s2 !== null) { + var l1 = s1.left; + var v1 = s1.key; + var r1 = s1.right; + var pres = [/* false */0]; + var match = splitAuxPivot(s2, v1, pres); + var ll = inter(l1, match[0]); + var rr = inter(r1, match[1]); + if (pres[0]) { + return Bs_internalAVLset.joinShared(ll, v1, rr); + } else { + return Bs_internalAVLset.concatShared(ll, rr); + } + } else { + return null; + } + } else { + return null; + } +} + +function diff(s1, s2) { + if (s1 !== null) { + if (s2 !== null) { + var l1 = s1.left; + var v1 = s1.key; + var r1 = s1.right; + var pres = [/* false */0]; + var match = splitAuxPivot(s2, v1, pres); + var ll = diff(l1, match[0]); + var rr = diff(r1, match[1]); + if (pres[0]) { + return Bs_internalAVLset.concatShared(ll, rr); + } else { + return Bs_internalAVLset.joinShared(ll, v1, rr); + } + } else { + return s1; + } + } else { + return s1; + } +} + var empty = Bs_internalAVLset.empty0; var isEmpty = Bs_internalAVLset.isEmpty0; @@ -15,12 +185,6 @@ var singleton = Bs_internalAVLset.singleton0; var remove = Bs_internalSetString.remove; -var union = Bs_internalSetString.union; - -var inter = Bs_internalSetString.inter; - -var diff = Bs_internalSetString.diff; - var cmp = Bs_internalSetString.cmp; var eq = Bs_internalSetString.eq; @@ -57,8 +221,6 @@ var maxOpt = Bs_internalAVLset.maxOpt0; var maxNull = Bs_internalAVLset.maxNull0; -var split = Bs_internalSetString.split; - var findOpt = Bs_internalSetString.findOpt; var checkInvariant = Bs_internalAVLset.checkInvariant; diff --git a/lib/js/bs_internalSetBuckets.js b/lib/js/bs_internalSetBuckets.js index 70914793529..3790cdbec84 100644 --- a/lib/js/bs_internalSetBuckets.js +++ b/lib/js/bs_internalSetBuckets.js @@ -2,7 +2,7 @@ var Bs_Array = require("./bs_Array.js"); -function bucket_length(_accu, _buckets) { +function bucketLength(_accu, _buckets) { while(true) { var buckets = _buckets; var accu = _accu; @@ -17,7 +17,7 @@ function bucket_length(_accu, _buckets) { }; } -function do_bucket_iter(f, _buckets) { +function doBucketIter(f, _buckets) { while(true) { var buckets = _buckets; if (buckets !== undefined) { @@ -34,7 +34,7 @@ function do_bucket_iter(f, _buckets) { function iter0(h, f) { var d = h.buckets; for(var i = 0 ,i_finish = d.length - 1 | 0; i <= i_finish; ++i){ - do_bucket_iter(f, d[i]); + doBucketIter(f, d[i]); } return /* () */0; } @@ -70,7 +70,7 @@ function toArray0(h) { return arr; } -function do_bucket_fold(f, _b, _accu) { +function doBucketFold(f, _b, _accu) { while(true) { var accu = _accu; var b = _b; @@ -89,14 +89,14 @@ function fold0(h, init, f) { var d = h.buckets; var accu = init; for(var i = 0 ,i_finish = d.length - 1 | 0; i <= i_finish; ++i){ - accu = do_bucket_fold(f, d[i], accu); + accu = doBucketFold(f, d[i], accu); } return accu; } function logStats0(h) { var mbl = Bs_Array.foldLeft(h.buckets, 0, (function (m, b) { - var len = bucket_length(0, b); + var len = bucketLength(0, b); if (m > len) { return m; } else { @@ -107,7 +107,7 @@ function logStats0(h) { return 0; })); Bs_Array.iter(h.buckets, (function (b) { - var l = bucket_length(0, b); + var l = bucketLength(0, b); histo[l] = histo[l] + 1 | 0; return /* () */0; })); diff --git a/lib/js/bs_internalSetInt.js b/lib/js/bs_internalSetInt.js index 7ce9940d6bf..862e2e2b519 100644 --- a/lib/js/bs_internalSetInt.js +++ b/lib/js/bs_internalSetInt.js @@ -131,176 +131,6 @@ function eq(s1, s2) { return +(cmp(s1, s2) === 0); } -function splitAuxNoPivot(n, x) { - var l = n.left; - var v = n.key; - var r = n.right; - if (x === v) { - return /* tuple */[ - l, - r - ]; - } else if (x < v) { - if (l !== null) { - var match = splitAuxNoPivot(l, x); - return /* tuple */[ - match[0], - Bs_internalAVLset.joinShared(match[1], v, r) - ]; - } else { - return /* tuple */[ - null, - n - ]; - } - } else if (r !== null) { - var match$1 = splitAuxNoPivot(r, x); - return /* tuple */[ - Bs_internalAVLset.joinShared(l, v, match$1[0]), - match$1[1] - ]; - } else { - return /* tuple */[ - n, - null - ]; - } -} - -function splitAuxPivot(n, x, pres) { - var l = n.left; - var v = n.key; - var r = n.right; - if (x === v) { - pres[0] = /* true */1; - return /* tuple */[ - l, - r - ]; - } else if (x < v) { - if (l !== null) { - var match = splitAuxPivot(l, x, pres); - return /* tuple */[ - match[0], - Bs_internalAVLset.joinShared(match[1], v, r) - ]; - } else { - return /* tuple */[ - null, - n - ]; - } - } else if (r !== null) { - var match$1 = splitAuxPivot(r, x, pres); - return /* tuple */[ - Bs_internalAVLset.joinShared(l, v, match$1[0]), - match$1[1] - ]; - } else { - return /* tuple */[ - n, - null - ]; - } -} - -function split(t, x) { - if (t !== null) { - var pres = [/* false */0]; - var v = splitAuxPivot(t, x, pres); - return /* tuple */[ - v, - pres[0] - ]; - } else { - return /* tuple */[ - /* tuple */[ - null, - null - ], - /* false */0 - ]; - } -} - -function union(s1, s2) { - if (s1 !== null) { - if (s2 !== null) { - var h1 = s1.h; - var h2 = s2.h; - if (h1 >= h2) { - if (h2 === 1) { - return add(s1, s2.key); - } else { - var l1 = s1.left; - var v1 = s1.key; - var r1 = s1.right; - var match = splitAuxNoPivot(s2, v1); - return Bs_internalAVLset.joinShared(union(l1, match[0]), v1, union(r1, match[1])); - } - } else if (h1 === 1) { - return add(s2, s1.key); - } else { - var l2 = s2.left; - var v2 = s2.key; - var r2 = s2.right; - var match$1 = splitAuxNoPivot(s1, v2); - return Bs_internalAVLset.joinShared(union(match$1[0], l2), v2, union(match$1[1], r2)); - } - } else { - return s1; - } - } else { - return s2; - } -} - -function inter(s1, s2) { - if (s1 !== null) { - if (s2 !== null) { - var l1 = s1.left; - var v1 = s1.key; - var r1 = s1.right; - var pres = [/* false */0]; - var match = splitAuxPivot(s2, v1, pres); - var ll = inter(l1, match[0]); - var rr = inter(r1, match[1]); - if (pres[0]) { - return Bs_internalAVLset.joinShared(ll, v1, rr); - } else { - return Bs_internalAVLset.concatShared(ll, rr); - } - } else { - return null; - } - } else { - return null; - } -} - -function diff(s1, s2) { - if (s1 !== null) { - if (s2 !== null) { - var l1 = s1.left; - var v1 = s1.key; - var r1 = s1.right; - var pres = [/* false */0]; - var match = splitAuxPivot(s2, v1, pres); - var ll = diff(l1, match[0]); - var rr = diff(r1, match[1]); - if (pres[0]) { - return Bs_internalAVLset.concatShared(ll, rr); - } else { - return Bs_internalAVLset.joinShared(ll, v1, rr); - } - } else { - return s1; - } - } else { - return s1; - } -} - function subset(_s1, _s2) { while(true) { var s2 = _s2; @@ -448,12 +278,6 @@ exports.remove = remove; exports.compareAux = compareAux; exports.cmp = cmp; exports.eq = eq; -exports.splitAuxNoPivot = splitAuxNoPivot; -exports.splitAuxPivot = splitAuxPivot; -exports.split = split; -exports.union = union; -exports.inter = inter; -exports.diff = diff; exports.subset = subset; exports.findOpt = findOpt; exports.findNull = findNull; diff --git a/lib/js/bs_internalSetString.js b/lib/js/bs_internalSetString.js index 7ce9940d6bf..862e2e2b519 100644 --- a/lib/js/bs_internalSetString.js +++ b/lib/js/bs_internalSetString.js @@ -131,176 +131,6 @@ function eq(s1, s2) { return +(cmp(s1, s2) === 0); } -function splitAuxNoPivot(n, x) { - var l = n.left; - var v = n.key; - var r = n.right; - if (x === v) { - return /* tuple */[ - l, - r - ]; - } else if (x < v) { - if (l !== null) { - var match = splitAuxNoPivot(l, x); - return /* tuple */[ - match[0], - Bs_internalAVLset.joinShared(match[1], v, r) - ]; - } else { - return /* tuple */[ - null, - n - ]; - } - } else if (r !== null) { - var match$1 = splitAuxNoPivot(r, x); - return /* tuple */[ - Bs_internalAVLset.joinShared(l, v, match$1[0]), - match$1[1] - ]; - } else { - return /* tuple */[ - n, - null - ]; - } -} - -function splitAuxPivot(n, x, pres) { - var l = n.left; - var v = n.key; - var r = n.right; - if (x === v) { - pres[0] = /* true */1; - return /* tuple */[ - l, - r - ]; - } else if (x < v) { - if (l !== null) { - var match = splitAuxPivot(l, x, pres); - return /* tuple */[ - match[0], - Bs_internalAVLset.joinShared(match[1], v, r) - ]; - } else { - return /* tuple */[ - null, - n - ]; - } - } else if (r !== null) { - var match$1 = splitAuxPivot(r, x, pres); - return /* tuple */[ - Bs_internalAVLset.joinShared(l, v, match$1[0]), - match$1[1] - ]; - } else { - return /* tuple */[ - n, - null - ]; - } -} - -function split(t, x) { - if (t !== null) { - var pres = [/* false */0]; - var v = splitAuxPivot(t, x, pres); - return /* tuple */[ - v, - pres[0] - ]; - } else { - return /* tuple */[ - /* tuple */[ - null, - null - ], - /* false */0 - ]; - } -} - -function union(s1, s2) { - if (s1 !== null) { - if (s2 !== null) { - var h1 = s1.h; - var h2 = s2.h; - if (h1 >= h2) { - if (h2 === 1) { - return add(s1, s2.key); - } else { - var l1 = s1.left; - var v1 = s1.key; - var r1 = s1.right; - var match = splitAuxNoPivot(s2, v1); - return Bs_internalAVLset.joinShared(union(l1, match[0]), v1, union(r1, match[1])); - } - } else if (h1 === 1) { - return add(s2, s1.key); - } else { - var l2 = s2.left; - var v2 = s2.key; - var r2 = s2.right; - var match$1 = splitAuxNoPivot(s1, v2); - return Bs_internalAVLset.joinShared(union(match$1[0], l2), v2, union(match$1[1], r2)); - } - } else { - return s1; - } - } else { - return s2; - } -} - -function inter(s1, s2) { - if (s1 !== null) { - if (s2 !== null) { - var l1 = s1.left; - var v1 = s1.key; - var r1 = s1.right; - var pres = [/* false */0]; - var match = splitAuxPivot(s2, v1, pres); - var ll = inter(l1, match[0]); - var rr = inter(r1, match[1]); - if (pres[0]) { - return Bs_internalAVLset.joinShared(ll, v1, rr); - } else { - return Bs_internalAVLset.concatShared(ll, rr); - } - } else { - return null; - } - } else { - return null; - } -} - -function diff(s1, s2) { - if (s1 !== null) { - if (s2 !== null) { - var l1 = s1.left; - var v1 = s1.key; - var r1 = s1.right; - var pres = [/* false */0]; - var match = splitAuxPivot(s2, v1, pres); - var ll = diff(l1, match[0]); - var rr = diff(r1, match[1]); - if (pres[0]) { - return Bs_internalAVLset.concatShared(ll, rr); - } else { - return Bs_internalAVLset.joinShared(ll, v1, rr); - } - } else { - return s1; - } - } else { - return s1; - } -} - function subset(_s1, _s2) { while(true) { var s2 = _s2; @@ -448,12 +278,6 @@ exports.remove = remove; exports.compareAux = compareAux; exports.cmp = cmp; exports.eq = eq; -exports.splitAuxNoPivot = splitAuxNoPivot; -exports.splitAuxPivot = splitAuxPivot; -exports.split = split; -exports.union = union; -exports.inter = inter; -exports.diff = diff; exports.subset = subset; exports.findOpt = findOpt; exports.findNull = findNull; From 390ce36b55dbd64544c8347fbe1db1c8210058ce Mon Sep 17 00:00:00 2001 From: Hongbo Zhang Date: Sat, 13 Jan 2018 10:00:15 +0800 Subject: [PATCH 3/3] remove pos variance ( Bs_Map.empty has to be monomorphic), prepare mutation --- jscomp/others/bs_Map.ml | 2 +- jscomp/others/bs_Map.mli | 2 +- jscomp/others/bs_MapInt.ml | 2 +- jscomp/others/bs_MapInt.mli | 2 +- jscomp/others/bs_MapString.ml | 2 +- jscomp/others/bs_MapString.mli | 2 +- jscomp/others/bs_internalAVLtree.ml | 12 ++++++------ jscomp/others/bs_internalAVLtree.mli | 2 +- jscomp/others/map.cppo.ml | 2 +- jscomp/others/map.cppo.mli | 2 +- jscomp/test/bs_map_test.js | 13 +++++++++++++ jscomp/test/bs_map_test.ml | 9 ++++++--- 12 files changed, 34 insertions(+), 18 deletions(-) diff --git a/jscomp/others/bs_Map.ml b/jscomp/others/bs_Map.ml index 043dee7909b..ed43c582333 100644 --- a/jscomp/others/bs_Map.ml +++ b/jscomp/others/bs_Map.ml @@ -14,7 +14,7 @@ module N = Bs_internalAVLtree module B = Bs_Bag -type ('key, + 'a, 'id) t0 = ('key,'a) N.t0 +type ('key, 'a, 'id) t0 = ('key,'a) N.t0 type ('k,'v,'id) t = (('k,'id) Bs_Cmp.t, diff --git a/jscomp/others/bs_Map.mli b/jscomp/others/bs_Map.mli index 3c77c273a51..d5c79033d19 100644 --- a/jscomp/others/bs_Map.mli +++ b/jscomp/others/bs_Map.mli @@ -12,7 +12,7 @@ (***********************************************************************) (** Adapted by authors of BuckleScript without using functors *) (** The type of the map keys. *) -type ('k, + 'a, 'id) t0 +type ('k, 'a, 'id) t0 (** [('k, 'a, id) t] ['k] the key type ['a] the value type diff --git a/jscomp/others/bs_MapInt.ml b/jscomp/others/bs_MapInt.ml index 33d195924c5..c3d12d742d8 100644 --- a/jscomp/others/bs_MapInt.ml +++ b/jscomp/others/bs_MapInt.ml @@ -6,7 +6,7 @@ module N = Bs_internalAVLtree type ('key, 'a, 'id) t0 = ('key,'a) N.t0 -type + 'a t = (key,'a) N.t0 +type 'a t = (key,'a) N.t0 diff --git a/jscomp/others/bs_MapInt.mli b/jscomp/others/bs_MapInt.mli index f68aad2071c..9742e997b40 100644 --- a/jscomp/others/bs_MapInt.mli +++ b/jscomp/others/bs_MapInt.mli @@ -1,7 +1,7 @@ # 4 "map.cppo.mli" type key = int # 8 -type (+'a) t +type 'a t (** The type of maps from type [key] to type ['a]. *) val empty: 'a t diff --git a/jscomp/others/bs_MapString.ml b/jscomp/others/bs_MapString.ml index 02ac3878d77..8b612e778a6 100644 --- a/jscomp/others/bs_MapString.ml +++ b/jscomp/others/bs_MapString.ml @@ -6,7 +6,7 @@ module N = Bs_internalAVLtree type ('key, 'a, 'id) t0 = ('key,'a) N.t0 -type + 'a t = (key,'a) N.t0 +type 'a t = (key,'a) N.t0 diff --git a/jscomp/others/bs_MapString.mli b/jscomp/others/bs_MapString.mli index 856ee854eac..1b274b1d5c1 100644 --- a/jscomp/others/bs_MapString.mli +++ b/jscomp/others/bs_MapString.mli @@ -1,7 +1,7 @@ # 2 "map.cppo.mli" type key = string # 8 -type (+'a) t +type 'a t (** The type of maps from type [key] to type ['a]. *) val empty: 'a t diff --git a/jscomp/others/bs_internalAVLtree.ml b/jscomp/others/bs_internalAVLtree.ml index 868584b4edd..4ceab1d1879 100644 --- a/jscomp/others/bs_internalAVLtree.ml +++ b/jscomp/others/bs_internalAVLtree.ml @@ -13,12 +13,12 @@ (** Almost rewritten by authors of BuckleScript *) -type ('k, + 'v) node = { - left : ('k,'v) node Js.null; - key : 'k; - value : 'v; - right : ('k,'v) node Js.null; - h : int +type ('k, 'v) node = { + mutable left : ('k,'v) node Js.null; + mutable key : 'k; + mutable value : 'v; + mutable right : ('k,'v) node Js.null; + mutable h : int } [@@bs.deriving abstract] external toOpt : 'a Js.null -> 'a option = "#null_to_opt" diff --git a/jscomp/others/bs_internalAVLtree.mli b/jscomp/others/bs_internalAVLtree.mli index 5ec85a23be2..032bb42f667 100644 --- a/jscomp/others/bs_internalAVLtree.mli +++ b/jscomp/others/bs_internalAVLtree.mli @@ -26,7 +26,7 @@ type ('key, 'a) t0 = ('key, 'a) node Js.null -and ('k, + 'v) node = { +and ('k, 'v) node = { left : ('k,'v) t0; key : 'k; value : 'v; diff --git a/jscomp/others/map.cppo.ml b/jscomp/others/map.cppo.ml index ea4b45fb245..ba812119abf 100644 --- a/jscomp/others/map.cppo.ml +++ b/jscomp/others/map.cppo.ml @@ -10,7 +10,7 @@ module N = Bs_internalAVLtree type ('key, 'a, 'id) t0 = ('key,'a) N.t0 -type + 'a t = (key,'a) N.t0 +type 'a t = (key,'a) N.t0 diff --git a/jscomp/others/map.cppo.mli b/jscomp/others/map.cppo.mli index b4eb6809ab8..d0c0f195c9e 100644 --- a/jscomp/others/map.cppo.mli +++ b/jscomp/others/map.cppo.mli @@ -5,7 +5,7 @@ type key = int #else [%error "unknown type"] #endif -type (+'a) t +type 'a t (** The type of maps from type [key] to type ['a]. *) val empty: 'a t diff --git a/jscomp/test/bs_map_test.js b/jscomp/test/bs_map_test.js index c54d2abeaad..7282c227063 100644 --- a/jscomp/test/bs_map_test.js +++ b/jscomp/test/bs_map_test.js @@ -2,6 +2,7 @@ var Bs_Map = require("../../lib/js/bs_Map.js"); var Bs_Set = require("../../lib/js/bs_Set.js"); +var Bs_MapInt = require("../../lib/js/bs_MapInt.js"); var Caml_primitive = require("../../lib/js/caml_primitive.js"); var Bs_internalAVLset = require("../../lib/js/bs_internalAVLset.js"); var Bs_internalAVLtree = require("../../lib/js/bs_internalAVLtree.js"); @@ -71,16 +72,28 @@ for(var i$1 = 0; i$1 <= 100000; ++i$1){ console.log(data$1); +var M = 0; + +var MI = 0; + +var vv = Bs_MapInt.empty; + +var vv2 = Bs_MapInt.empty; + var B = 0; var ISet = 0; exports.N = N; +exports.M = M; +exports.MI = MI; exports.m0 = m0; exports.I = I; exports.I2 = I2; exports.m = m; exports.m2 = m2; +exports.vv = vv; +exports.vv2 = vv2; exports.B = B; exports.ISet = ISet; /* data Not a pure module */ diff --git a/jscomp/test/bs_map_test.ml b/jscomp/test/bs_map_test.ml index 9ca4099f54d..2561d1cfbfc 100644 --- a/jscomp/test/bs_map_test.ml +++ b/jscomp/test/bs_map_test.ml @@ -5,8 +5,9 @@ module N = compare x y ) ) - -let m0 = Bs.Map.empty (module N) +module M = Bs.Map +module MI = Bs.MapInt +let m0 : (_,string,_) M.t = M.empty (module N) module I = Bs.Cmp.Make( struct @@ -26,8 +27,10 @@ module I2 = Bs.Cmp.Make( let m = Bs.Map.empty (module I) -let m2 = Bs.Map.empty (module I2) +let m2 : (int, string, _) M.t = M.empty (module I2) +let vv = MI.empty +let vv2 = MI.empty module B = Bs.Bag (* let () = Js.log (m = m2) *)