From be40e2e33baff155ab2dc68f063987079295156c Mon Sep 17 00:00:00 2001 From: Hongbo Zhang Date: Thu, 1 Feb 2018 11:14:04 +0800 Subject: [PATCH 1/6] tweak hashmap --- jscomp/others/bs_HashMap.ml | 57 +++-- jscomp/others/bs_HashMap.mli | 4 - jscomp/others/bs_HashMultiMap.ml | 275 ++++++++++++---------- jscomp/others/bs_HashMultiMap.mli | 83 ++++--- jscomp/others/bs_internalBuckets.ml | 9 +- lib/js/bs_HashMap.js | 23 +- lib/js/bs_HashMultiMap.js | 350 +++++++++++++--------------- 7 files changed, 390 insertions(+), 411 deletions(-) diff --git a/jscomp/others/bs_HashMap.ml b/jscomp/others/bs_HashMap.ml index dd6b5509ba..4e11ce7795 100644 --- a/jscomp/others/bs_HashMap.ml +++ b/jscomp/others/bs_HashMap.ml @@ -24,12 +24,25 @@ type ('a,'b,'id) t = ( ('a, 'id) hash, ('a, 'id) eq, 'a, 'b) N.t +let clear = C.clear +let size = C.size +let forEach = N.forEach +let reduce = N.reduce +let logStats = N.logStats +let keepMapInPlace = N.keepMapInPlace +let toArray = N.toArray +let copy = N.copy +let keysToArray = N.keysToArray +let valuesToArray = N.valuesToArray +let getBucketHistogram = N.getBucketHistogram +let isEmpty = C.isEmpty + let rec copyBucketReHash ~hash ~h_buckets ~ndata_tail old_bucket = match C.toOpt old_bucket with | None -> () | Some cell -> - let nidx = (Bs_Dict.getHashInternal hash) (N.key cell) [@bs] land (A.length h_buckets - 1) in + let nidx = hash (N.key cell) [@bs] land (A.length h_buckets - 1) in let v = C.return cell in begin match C.toOpt (A.getUnsafe ndata_tail nidx) with | None -> @@ -60,7 +73,7 @@ let resize ~hash h = end let rec replaceInBucket ~eq key info cell = - if (Bs_Dict.getEqInternal eq) (N.key cell) key [@bs] + if eq (N.key cell) key [@bs] then begin N.valueSet cell info; @@ -75,7 +88,7 @@ let rec replaceInBucket ~eq key info cell = let set0 h key value ~eq ~hash = let h_buckets = C.buckets h in let buckets_len = A.length h_buckets in - let i = (Bs_Dict.getHashInternal hash) key [@bs] land (buckets_len - 1) in + let i = hash key [@bs] land (buckets_len - 1) in let l = A.getUnsafe h_buckets i in (match C.toOpt l with | None -> @@ -93,15 +106,16 @@ let set0 h key value ~eq ~hash = Here we add it to the head, it could be tail *) let set h key value = - let eq, hash = C.eq h, C.hash h in - set0 h key value ~eq ~hash + set0 h key value + ~eq:(Bs_Dict.getEqInternal (C.eq h)) + ~hash:(Bs_Dict.getHashInternal (C.hash h)) let rec removeInBucket h h_buckets i key prec bucket ~eq = match C.toOpt bucket with | None -> () | Some cell -> let cell_next = N.next cell in - if (Bs_Dict.getEqInternal eq) (N.key cell) key [@bs] + if eq (N.key cell) key [@bs] then begin N.nextSet prec cell_next ; @@ -111,14 +125,14 @@ let rec removeInBucket h h_buckets i key prec bucket ~eq = let remove h key = - let eq = C.eq h in let h_buckets = C.buckets h in let i = (Bs_Dict.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in let bucket = A.getUnsafe h_buckets i in match C.toOpt bucket with | None -> () | Some cell -> - if (Bs_Dict.getEqInternal eq) (N.key cell ) key [@bs] then + let eq = (Bs_Dict.getEqInternal (C.eq h)) in + if eq (N.key cell ) key [@bs] then begin A.setUnsafe h_buckets i (N.next cell); C.sizeSet h (C.size h - 1) @@ -136,12 +150,12 @@ let rec getAux ~eq key buckets = else getAux ~eq key (N.next cell) let get h key = - let eq = Bs_Dict.getEqInternal (C.eq h) in let h_buckets = C.buckets h in let nid = (Bs_Dict.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in match C.toOpt @@ A.getUnsafe h_buckets nid with | None -> None | Some cell1 -> + let eq = Bs_Dict.getEqInternal (C.eq h) in if eq key (N.key cell1) [@bs] then Some (N.value cell1) else @@ -159,7 +173,7 @@ let get h key = getAux ~eq key (N.next cell3) -let rec memInBucket ~eq key cell = +let rec memInBucket key cell ~eq = eq (N.key cell) key [@bs] || (match C.toOpt (N.next cell) with | None -> false @@ -167,14 +181,13 @@ let rec memInBucket ~eq key cell = memInBucket ~eq key nextCell) let has h key = - let eq = Bs_Dict.getEqInternal (C.eq h) in let h_buckets = C.buckets h in let nid = (Bs_Dict.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in let bucket = A.getUnsafe h_buckets nid in match C.toOpt bucket with | None -> false | Some bucket -> - memInBucket ~eq key bucket + memInBucket ~eq:(Bs_Dict.getEqInternal (C.eq h)) key bucket @@ -183,27 +196,13 @@ let make (type elt) (type id) initialize_size ~(dict : (elt,id) dict) = let module M = (val dict) in C.make ~hash:M.hash ~eq:M.eq initialize_size -let clear = C.clear -let size = C.size -let forEach = N.forEach -let reduce = N.reduce -let logStats = N.logStats -let keepMapInPlace = N.keepMapInPlace -let toArray = N.toArray -let copy = N.copy -let keysToArray = N.keysToArray -let valuesToArray = N.valuesToArray -let getBucketHistogram = N.getBucketHistogram -let isEmpty = C.isEmpty - - - let ofArray (type a) (type id) arr ~dict:(dict:(a,id) dict) = let module M = (val dict) in - let eq, hash = M.eq, M.hash in + let hash, eq = M.hash, M.eq in let len = A.length arr in let v = C.make ~hash ~eq len in + let eq, hash = Bs_Dict.getEqInternal eq, Bs_Dict.getHashInternal hash in for i = 0 to len - 1 do let key,value = (A.getUnsafe arr i) in set0 ~eq ~hash v key value @@ -211,7 +210,7 @@ let ofArray (type a) (type id) arr ~dict:(dict:(a,id) dict) = v let mergeMany h arr = - let hash, eq = C.hash h , C.eq h in + let hash, eq = Bs_Dict.getHashInternal ( C.hash h) , Bs_Dict.getEqInternal (C.eq h) in let len = A.length arr in for i = 0 to len - 1 do let key,value = (A.getUnsafe arr i) in diff --git a/jscomp/others/bs_HashMap.mli b/jscomp/others/bs_HashMap.mli index 8f7fffd1e0..cddb114760 100644 --- a/jscomp/others/bs_HashMap.mli +++ b/jscomp/others/bs_HashMap.mli @@ -95,10 +95,6 @@ val ofArray: ('key * 'value) array -> dict:('key,'id) dict -> ('key, 'value, 'id val mergeMany: ('key, 'value, 'id ) t -> ('key * 'value) array -> unit val getBucketHistogram: _ t -> int array val logStats: _ t -> unit -(** [logStats tbl] returns statistics about the table [tbl]: - number of buckets, size of the biggest bucket, distribution of - buckets by size. -*) diff --git a/jscomp/others/bs_HashMultiMap.ml b/jscomp/others/bs_HashMultiMap.ml index baf291d0ac..3f3166fb65 100644 --- a/jscomp/others/bs_HashMultiMap.ml +++ b/jscomp/others/bs_HashMultiMap.ml @@ -22,12 +22,25 @@ type ('a, 'id) dict = ('a, 'id) Bs_Dict.hashable type ('a, 'b,'id) t = ( ('a, 'id) hash, ('a, 'id) eq , 'a,'b) N.t +let clear = C.clear +let size = C.size +let forEach = N.forEach +let reduce = N.reduce +let logStats = N.logStats +let keepMapInPlace = N.keepMapInPlace +let toArray = N.toArray +let copy = N.copy +let keysToArray = N.keysToArray +let valuesToArray = N.valuesToArray +let getBucketHistogram = N.getBucketHistogram +let isEmpty = C.isEmpty -let rec insert_bucket ~hash ~h_buckets ~ndata_tail h old_bucket = + +let rec copyBucketReHash ~hash ~h_buckets ~ndata_tail old_bucket = match C.toOpt old_bucket with | None -> () | Some cell -> - let nidx = (Bs_Dict.getHashInternal hash) (N.key cell) [@bs] land (Array.length h_buckets - 1) in + let nidx = hash (N.key cell) [@bs] land (A.length h_buckets - 1) in let v = C.return cell in begin match C.toOpt (A.getUnsafe ndata_tail nidx) with | None -> @@ -36,19 +49,19 @@ let rec insert_bucket ~hash ~h_buckets ~ndata_tail h old_bucket = N.nextSet tail v (* cell put at the end *) end; A.setUnsafe ndata_tail nidx v; - insert_bucket ~hash ~h_buckets ~ndata_tail h (N.next cell) + copyBucketReHash ~hash ~h_buckets ~ndata_tail (N.next cell) let resize ~hash h = let odata = C.buckets h in - let osize = Array.length odata in + let osize = A.length odata in let nsize = osize * 2 in if nsize >= osize then begin (* no overflow *) 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 (A.getUnsafe odata i) + copyBucketReHash ~hash ~h_buckets ~ndata_tail (A.getUnsafe odata i) done; for i = 0 to nsize - 1 do match C.toOpt (A.getUnsafe ndata_tail i) with @@ -57,185 +70,189 @@ let resize ~hash h = done end - -let add0 ~hash h key value = - let h_buckets = C.buckets h in - let h_buckets_lenth = Array.length h_buckets in - let i = (Bs_Dict.getHashInternal hash) key [@bs] land (h_buckets_lenth - 1) in - let bucket = - N.bucket ~key ~value ~next:(A.getUnsafe h_buckets i) in - A.setUnsafe 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 C.toOpt buckets with +let rec replaceFirst ~eq key info cell = + if eq (N.key cell) key [@bs] + then + begin + N.valueSet cell info; + false + end + else + match C.toOpt (N.next cell) with + | None -> true + | Some cell -> + replaceFirst ~eq key info cell + +(* + Since we are replacing the first one in the bucket, + it requires when adding new element, the newer comes in + the head, so that replace will replace the latest one + [add tbl 10 '0'; add tbl 10 '1'] + the replacement will replace [10,'1'] +*) +let replaceBy h key value ~eq ~hash = + let h_buckets = C.buckets h in + let buckets_len = A.length h_buckets in + let hash, eq = Bs_Dict.getHashInternal hash , Bs_Dict.getEqInternal eq in + let i = hash key [@bs] land (buckets_len - 1) in + let l = A.getUnsafe h_buckets i in + (match C.toOpt l with + | None -> + A.setUnsafe h_buckets i (C.return (N.bucket ~key ~value ~next:C.emptyOpt)); + C.sizeSet h (C.size h + 1); + | Some bucket -> + if replaceFirst ~eq key value bucket then begin + A.setUnsafe h_buckets i (C.return (N.bucket ~key ~value ~next:l)); + C.sizeSet h (C.size h + 1); + end + ); + if C.size h > buckets_len lsl 1 then resize ~hash h + +let replace h key value = + replaceBy h key value ~eq:(C.eq h) ~hash:(C.hash h) + +let rec removeInBucket h h_buckets i key prec bucket ~eq = + match C.toOpt bucket with | None -> () | Some cell -> let cell_next = N.next cell in - if (Bs_Dict.getEqInternal eq) (N.key cell) key [@bs] + if eq (N.key cell) key [@bs] then begin - (match C.toOpt prec with - | None -> A.setUnsafe h_buckets i cell_next - | Some c -> N.nextSet c cell_next); - C.sizeSet h (C.size h - 1); + N.nextSet prec cell_next ; + C.sizeSet h (C.size h - 1); end - else remove_bucket ~eq h h_buckets i key buckets cell_next + else removeInBucket ~eq h h_buckets i key cell cell_next -let remove0 ~hash ~eq h key = - let h_buckets = C.buckets h in - let i = (Bs_Dict.getHashInternal hash) key [@bs] land (Array.length h_buckets - 1) in - remove_bucket ~eq h h_buckets i key C.emptyOpt (A.getUnsafe h_buckets i) -let rec removeAllBuckets ~eq h h_buckets i key prec buckets = - match C.toOpt buckets with - | None -> () - | Some cell -> - let cell_next = N.next cell in - if (Bs_Dict.getEqInternal eq) (N.key cell) key [@bs] - then - begin - (match C.toOpt prec with - | None -> A.setUnsafe h_buckets i cell_next - | Some c -> N.nextSet c cell_next); - 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 remove h key = let h_buckets = C.buckets h in - let i = (Bs_Dict.getHashInternal hash) key [@bs] land (Array.length h_buckets - 1) in - removeAllBuckets ~eq h h_buckets i key C.emptyOpt (A.getUnsafe h_buckets i) - - -let rec find_rec ~eq key buckets = + let i = (Bs_Dict.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in + let bucket = (A.getUnsafe h_buckets i) in + match C.toOpt bucket with + | None -> () + | Some cell -> + let eq = (Bs_Dict.getEqInternal (C.eq h)) in + if eq (N.key cell ) key [@bs] then + begin + A.setUnsafe h_buckets i (N.next cell); + C.sizeSet h (C.size h - 1) + end + else + removeInBucket ~eq h h_buckets i key cell (N.next cell) + +(* TODO: add [removeAll] *) + + +let rec getAux ~eq key buckets = match C.toOpt buckets with | None -> None | Some cell -> - if (Bs_Dict.getEqInternal eq) key (N.key cell) [@bs] then Some (N.value cell) - else find_rec ~eq key (N.next cell) + if eq key (N.key cell) [@bs] then Some (N.value cell) + else getAux ~eq key (N.next cell) -let get0 ~hash ~eq h key = +let get h key = let h_buckets = C.buckets h in - let nid = (Bs_Dict.getHashInternal hash) key [@bs] land (Array.length h_buckets - 1) in + let nid = (Bs_Dict.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in match C.toOpt @@ A.getUnsafe h_buckets nid with | None -> None | Some cell1 -> - if (Bs_Dict.getEqInternal eq) key (N.key cell1) [@bs] then + let eq = Bs_Dict.getEqInternal (C.eq h) in + if eq key (N.key cell1) [@bs] then Some (N.value cell1) else match C.toOpt (N.next cell1) with | None -> None | Some cell2 -> - if (Bs_Dict.getEqInternal eq) key - (N.key cell2) [@bs] then + if eq key (N.key cell2) [@bs] then Some (N.value cell2) else match C.toOpt (N.next cell2) with | None -> None | Some cell3 -> - if (Bs_Dict.getEqInternal eq) key - (N.key cell3) [@bs] then + if eq key (N.key cell3) [@bs] then Some (N.value cell3) else - find_rec ~eq key (N.next cell3) + getAux ~eq key (N.next cell3) - -let getAll0 ~hash ~eq h key = - let rec find_in_bucket buckets = +(*TODO: getAll stack-safe *) +(* let rec findAlInBucket buckets key ~eq = match C.toOpt buckets with | None -> [] | Some cell -> - if (Bs_Dict.getEqInternal eq) - (N.key cell) key [@bs] - then (N.value cell) :: find_in_bucket (N.next cell) - else find_in_bucket (N.next cell) in + if eq (N.key cell) key [@bs] + then (N.value cell) :: findAlInBucket (N.next cell) + else findAlInBucket (N.next cell) + +let getAll0 ~hash ~eq h key = let h_buckets = C.buckets h in - let nid = (Bs_Dict.getHashInternal hash) key [@bs] land (Array.length h_buckets - 1) in - find_in_bucket (A.getUnsafe h_buckets nid) + let nid = (Bs_Dict.getHashInternal hash) key [@bs] land (A.length h_buckets - 1) in + findAlInBucket (A.getUnsafe h_buckets nid) -let rec replace_bucket ~eq key info buckets = - match C.toOpt buckets with - | None -> - true - | Some cell -> - if (Bs_Dict.getEqInternal eq) (N.key cell) key [@bs] - then - begin - N.keySet cell key; - N.valueSet cell info; - false - end - else - replace_bucket ~eq key info (N.next cell) -let replace0 ~hash ~eq h key info = - let h_buckets = C.buckets h in - let i = (Bs_Dict.getHashInternal 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 - A.setUnsafe h_buckets i (C.return - (N.bucket ~key ~value:info ~next:l)); - 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 getAll h key = + getAll0 ~hash:(C.hash h) ~eq:(C.eq h) h key + *) + -let rec mem_in_bucket ~eq key cell = - (Bs_Dict.getEqInternal eq) - (N.key cell) key [@bs] || +let rec memInBucket key cell ~eq = + eq (N.key cell) key [@bs] || (match C.toOpt (N.next cell) with | None -> false | Some nextCell -> - mem_in_bucket ~eq key nextCell) + memInBucket ~eq key nextCell) -let has0 ~hash ~eq h key = +let has h key = let h_buckets = C.buckets h in - let nid = (Bs_Dict.getHashInternal hash) key [@bs] land (Array.length h_buckets - 1) in + let nid = (Bs_Dict.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in let bucket = (A.getUnsafe h_buckets nid) in match C.toOpt bucket with | None -> false | Some bucket -> - mem_in_bucket ~eq key bucket + memInBucket ~eq:(Bs_Dict.getEqInternal (C.eq h)) key bucket -let make = C.make -(* Wrapper *) let make (type elt) (type id) initialize_size ~(dict : (elt, id) dict) = let module M = (val dict) in C.make initialize_size ~hash:M.hash ~eq:M.eq -let clear = C.clear -let size = C.size -let forEach = N.forEach -let reduce = N.reduce -let logStats = N.logStats +(****************************************************************************) -let add h key info = - add0 ~hash:(C.hash h) h key info - -let remove h key = - remove0 ~hash:(C.hash h) ~eq:(C.eq h) h key - -let removeAll h key = - removeAll0 ~hash:(C.hash h) ~eq:(C.eq h) h key - -let get h key = - get0 ~hash:(C.hash h) ~eq:(C.eq h) h key - -let getAll h key = - getAll0 ~hash:(C.hash h) ~eq:(C.eq h) h key - -let replace h key info = - replace0 ~hash:(C.hash h) ~eq:(C.eq h) h key info +let add0 h key value ~hash = + let h_buckets = C.buckets h in + let buckets_lenth = A.length h_buckets in + let i = hash key [@bs] land (buckets_lenth - 1) in + let bucket = + N.bucket ~key ~value ~next:(A.getUnsafe h_buckets i) in + A.setUnsafe 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 > buckets_lenth lsl 1 then resize ~hash h -let has h key = - has0 ~hash:(C.hash h) ~eq:(C.eq h) h key -let keepMapInPlace = N.keepMapInPlace +let add h key info = + add0 ~hash:(Bs_Dict.getHashInternal (C.hash h)) h key info + +let ofArray (type a) (type id) arr ~dict:(dict:(a,id) dict) = + let module M = (val dict) in + let hash, eq = M.hash, M.eq in + let len = A.length arr in + let v = C.make ~hash ~eq len in + let hash = Bs_Dict.getHashInternal hash in + for i = 0 to len - 1 do + let key,value = (A.getUnsafe arr i) in + add0 ~hash v key value + done ; + v + +let mergeMany h arr = + let hash = Bs_Dict.getHashInternal ( C.hash h) in + let len = A.length arr in + for i = 0 to len - 1 do + let key,value = (A.getUnsafe arr i) in + add0 h ~hash key value + done + \ No newline at end of file diff --git a/jscomp/others/bs_HashMultiMap.mli b/jscomp/others/bs_HashMultiMap.mli index 5c3640e4c2..99bc177235 100644 --- a/jscomp/others/bs_HashMultiMap.mli +++ b/jscomp/others/bs_HashMultiMap.mli @@ -2,12 +2,14 @@ -type ('a,'b,'id) t +type ('key,'value,'id) t (** The type of hash tables from type ['a] to type ['b]. *) +type ('a, 'id) eq = ('a, 'id) Bs_Dict.eq +type ('a, 'id) hash = ('a, 'id) Bs_Dict.hash type ('a, 'id) dict = ('a, 'id) Bs_Dict.hashable - + val make : int -> dict: ('a, 'id) dict -> ('a,'b,'id) t (** [make n ~dict] creates a new, empty hash table, with initial size [n]. For best results, [n] should be on the @@ -18,11 +20,9 @@ val make : int -> dict: ('a, 'id) dict -> ('a,'b,'id) t val clear : ('a, 'b, 'id) t -> unit -(** Empty a hash table. Use [reset] instead of [clear] to shrink the - size of the bucket table to its initial size. *) - - +(** Empty a hash table. *) +val isEmpty: _ t -> bool val add: ('a, 'b, 'id) t -> 'a -> 'b -> unit @@ -32,49 +32,43 @@ val add: ('a, 'b, 'id) t -> 'a -> 'b -> unit the previous binding for [x], if any, is restored. (Same behavior as with association lists.) *) -val get: - ('a, 'b, 'id) t -> 'a -> 'b option -(** [get tbl x] returns the current binding of [x] in [tbl] *) + val replace: ('a, 'b, 'id) t -> 'a -> 'b -> unit +(** [replace tbl x y] replaces the current binding of [x] + in [tbl] by a binding of [x] to [y]. If [x] is unbound in [tbl], + a binding of [x] to [y] is added to [tbl]. + This is functionally equivalent to [remove tbl x] + followed by [add tbl x y]. *) + +val replaceBy: + ('key, 'value, 'id) t -> + 'key -> + 'value -> + eq:('key,'id) eq -> + hash:('key,'id) hash -> + unit +(** [replaceBy tbl k v ~eq ~hash] the same as + [replace tbl k v] except that [eq] and [hash] + is supplied directly so it can be batched (slightly faster) +*) + +val copy: ('key, 'value, 'id) t -> ('key, 'value, 'id) t -val getAll: ('a, 'b, 'id) t -> 'a -> 'b list -(** [getAll tbl x] returns the list of all data - associated with [x] in [tbl]. - The current binding is returned first, then the previous - bindings, in reverse order of introduction in the table. *) +val get: ('key, 'value, 'id) t -> 'key -> 'value option -val has: - ('a, 'b, 'id) t -> 'a -> bool + +val has: ('key, 'value, 'id) t -> 'key -> bool (** [has tbl x] checks if [x] is bound in [tbl]. *) -val remove: -('a, 'b, 'id) t -> 'a -> unit +val remove: ('key, 'value, 'id) t -> 'key -> unit (** [remove tbl x] removes the current binding of [x] in [tbl], restoring the previous binding if it exists. It does nothing if [x] is not bound in [tbl]. *) -val removeAll: -('a, 'b, 'id) t -> 'a -> unit - - -val replace: - ('a, 'b, 'id) t -> 'a -> 'b -> unit -(** [replace tbl x y] replaces the current binding of [x] - in [tbl] by a binding of [x] to [y]. If [x] is unbound in [tbl], - a binding of [x] to [y] is added to [tbl]. - This is functionally equivalent to [remove tbl x] - followed by [add tbl x y]. *) - - val forEach : ('a, 'b, 'id) t -> ('a -> 'b -> unit [@bs]) -> unit (** [forEach f tbl] applies [f] to all bindings in table [tbl]. [f] receives the key as first argument, and the associated value as second argument. Each binding is presented exactly once to [f]. - - The order in which the bindings are passed to [f] is unspecified. - However, if the table contains several bindings for the same key, - they are passed to [f] in reverse order of introduction, that is, - the most recent binding is passed first. *) @@ -89,17 +83,12 @@ val reduce : ('a, 'b, 'id) t -> 'c -> ('c -> 'a -> 'b -> 'c [@bs]) -> 'c However, if the table contains several bindings for the same key, they are passed to [f] in reverse order of introduction, that is, the most recent binding is passed first. - - If the hash table was created in non-randomized mode, the order - in which the bindings are enumerated is reproducible between - successive runs of the program, and even between minor versions - of OCaml. For randomized hash tables, the order of enumeration - is entirely random. *) +*) val keepMapInPlace : ('a, 'b, 'id) t -> ('a -> 'b -> 'b option [@bs]) -> unit -val size : ('a, 'b, 'id) t -> int +val size : _ t -> int (** [size tbl] returns the number of bindings in [tbl]. It takes constant time. Multiple bindings are counted once each, so [size] gives the number of times [forEach] calls its @@ -107,6 +96,12 @@ val size : ('a, 'b, 'id) t -> int - +val toArray: ('key, 'value, 'id ) t -> ('key * 'value) array +val keysToArray: ('key, _, _) t -> 'key array +val valuesToArray: (_,'value,_) t -> 'value array +val ofArray: ('key * 'value) array -> dict:('key,'id) dict -> ('key, 'value, 'id ) t +val mergeMany: ('key, 'value, 'id ) t -> ('key * 'value) array -> unit +val getBucketHistogram: _ t -> int array +val logStats: _ t -> unit val logStats : _ t -> unit diff --git a/jscomp/others/bs_internalBuckets.ml b/jscomp/others/bs_internalBuckets.ml index eac36540c0..4acea17996 100644 --- a/jscomp/others/bs_internalBuckets.ml +++ b/jscomp/others/bs_internalBuckets.ml @@ -35,12 +35,6 @@ and ('hash, 'eq, 'a, 'b) t = ('hash, 'eq, ('a,'b) bucket) C.container module A = Bs_Array -type statistics = { - num_bindings: int; - num_buckets: int; - max_bucket_length: int; - bucket_histogram: int array -} let rec copy ( x : _ t) : _ t= C.container @@ -214,3 +208,6 @@ let linear h f = let keysToArray h = linear h (fun [@bs] x -> key x) let valuesToArray h = linear h (fun [@bs] x -> value x) let toArray h = linear h (fun [@bs]x -> key x, value x) + + + diff --git a/lib/js/bs_HashMap.js b/lib/js/bs_HashMap.js index 8397f3c31c..0f6f8a50b1 100644 --- a/lib/js/bs_HashMap.js +++ b/lib/js/bs_HashMap.js @@ -3,6 +3,10 @@ var Bs_internalBuckets = require("./bs_internalBuckets.js"); var Bs_internalBucketsType = require("./bs_internalBucketsType.js"); +function size(prim) { + return prim.size; +} + function copyBucketReHash(hash, h_buckets, ndata_tail, _old_bucket) { while(true) { var old_bucket = _old_bucket; @@ -96,17 +100,15 @@ function set0(h, key, value, eq, hash) { } function set(h, key, value) { - var eq = h.eq; - var hash = h.hash; - return set0(h, key, value, eq, hash); + return set0(h, key, value, h.eq, h.hash); } function remove(h, key) { - var eq = h.eq; var h_buckets = h.buckets; var i = h.hash(key) & (h_buckets.length - 1 | 0); var bucket = h_buckets[i]; if (bucket !== undefined) { + var eq = h.eq; if (eq(bucket.key, key)) { h_buckets[i] = bucket.next; h.size = h.size - 1 | 0; @@ -143,11 +145,11 @@ function remove(h, key) { } function get(h, key) { - var eq = h.eq; var h_buckets = h.buckets; var nid = h.hash(key) & (h_buckets.length - 1 | 0); var match = h_buckets[nid]; if (match !== undefined) { + var eq = h.eq; if (eq(key, match.key)) { return /* Some */[match.value]; } else { @@ -193,17 +195,16 @@ function get(h, key) { } function has(h, key) { - var eq = h.eq; var h_buckets = h.buckets; var nid = h.hash(key) & (h_buckets.length - 1 | 0); var bucket = h_buckets[nid]; if (bucket !== undefined) { - var eq$1 = eq; var key$1 = key; var _cell = bucket; + var eq = h.eq; while(true) { var cell = _cell; - if (eq$1(cell.key, key$1)) { + if (eq(cell.key, key$1)) { return /* true */1; } else { var match = cell.next; @@ -225,13 +226,9 @@ function make(initialize_size, dict) { return Bs_internalBucketsType.make(dict[/* hash */0], dict[/* eq */1], initialize_size); } -function size(prim) { - return prim.size; -} - function ofArray(arr, dict) { - var eq = dict[/* eq */1]; var hash = dict[/* hash */0]; + var eq = dict[/* eq */1]; var len = arr.length; var v = Bs_internalBucketsType.make(hash, eq, len); for(var i = 0 ,i_finish = len - 1 | 0; i <= i_finish; ++i){ diff --git a/lib/js/bs_HashMultiMap.js b/lib/js/bs_HashMultiMap.js index b10d28fe70..8d726cc032 100644 --- a/lib/js/bs_HashMultiMap.js +++ b/lib/js/bs_HashMultiMap.js @@ -3,7 +3,11 @@ var Bs_internalBuckets = require("./bs_internalBuckets.js"); var Bs_internalBucketsType = require("./bs_internalBucketsType.js"); -function insert_bucket(hash, h_buckets, ndata_tail, _, _old_bucket) { +function size(prim) { + return prim.size; +} + +function copyBucketReHash(hash, h_buckets, ndata_tail, _old_bucket) { while(true) { var old_bucket = _old_bucket; if (old_bucket !== undefined) { @@ -33,7 +37,7 @@ function resize(hash, h) { var ndata_tail = new Array(nsize); h.buckets = h_buckets; for(var i = 0 ,i_finish = osize - 1 | 0; i <= i_finish; ++i){ - insert_bucket(hash, h_buckets, ndata_tail, h, odata[i]); + copyBucketReHash(hash, h_buckets, ndata_tail, odata[i]); } for(var i$1 = 0 ,i_finish$1 = nsize - 1 | 0; i$1 <= i_finish$1; ++i$1){ var match = ndata_tail[i$1]; @@ -48,161 +52,126 @@ function resize(hash, h) { } } -function replace_bucket(eq, key, info, _buckets) { +function replaceFirst(eq, key, info, _cell) { while(true) { - var buckets = _buckets; - if (buckets !== undefined) { - if (eq(buckets.key, key)) { - buckets.key = key; - buckets.value = info; - return /* false */0; - } else { - _buckets = buckets.next; + var cell = _cell; + if (eq(cell.key, key)) { + cell.value = info; + return /* false */0; + } else { + var match = cell.next; + if (match !== undefined) { + _cell = match; continue ; + } else { + return /* true */1; } - } else { - return /* true */1; } }; } -function make(initialize_size, dict) { - return Bs_internalBucketsType.make(dict[/* hash */0], dict[/* eq */1], initialize_size); -} - -function size(prim) { - return prim.size; -} - -function add(h, key, info) { - var hash = h.hash; - var h$1 = h; - var key$1 = key; - var value = info; - var h_buckets = h$1.buckets; - var h_buckets_lenth = h_buckets.length; - var i = hash(key$1) & (h_buckets_lenth - 1 | 0); - var bucket = { - key: key$1, - value: value, - next: h_buckets[i] - }; - h_buckets[i] = bucket; - var h_new_size = h$1.size + 1 | 0; - h$1.size = h_new_size; - if (h_new_size > (h_buckets_lenth << 1)) { - return resize(hash, h$1); +function replaceBy(h, key, value, eq, hash) { + var h_buckets = h.buckets; + var buckets_len = h_buckets.length; + var i = hash(key) & (buckets_len - 1 | 0); + var l = h_buckets[i]; + if (l !== undefined) { + if (replaceFirst(eq, key, value, l)) { + h_buckets[i] = { + key: key, + value: value, + next: l + }; + h.size = h.size + 1 | 0; + } + + } else { + h_buckets[i] = { + key: key, + value: value, + next: Bs_internalBucketsType.emptyOpt + }; + h.size = h.size + 1 | 0; + } + if (h.size > (buckets_len << 1)) { + return resize(hash, h); } else { return 0; } } -function remove(h, key) { - var hash = h.hash; - var eq = h.eq; - var h$1 = h; - var key$1 = key; - var h_buckets = h$1.buckets; - var i = hash(key$1) & (h_buckets.length - 1 | 0); - var eq$1 = eq; - var h$2 = h$1; - var h_buckets$1 = h_buckets; - var i$1 = i; - var key$2 = key$1; - var _prec = Bs_internalBucketsType.emptyOpt; - var _buckets = h_buckets[i]; - while(true) { - var buckets = _buckets; - var prec = _prec; - if (buckets !== undefined) { - var cell_next = buckets.next; - if (eq$1(buckets.key, key$2)) { - if (prec !== undefined) { - prec.next = cell_next; - } else { - h_buckets$1[i$1] = cell_next; - } - h$2.size = h$2.size - 1 | 0; - return /* () */0; - } else { - _buckets = cell_next; - _prec = buckets; - continue ; - - } - } else { - return /* () */0; - } - }; +function replace(h, key, value) { + return replaceBy(h, key, value, h.eq, h.hash); } -function removeAll(h, key) { - var hash = h.hash; - var eq = h.eq; - var h$1 = h; - var key$1 = key; - var h_buckets = h$1.buckets; - var i = hash(key$1) & (h_buckets.length - 1 | 0); - var eq$1 = eq; - var h$2 = h$1; - var h_buckets$1 = h_buckets; - var i$1 = i; - var key$2 = key$1; - var _prec = Bs_internalBucketsType.emptyOpt; - var _buckets = h_buckets[i]; - while(true) { - var buckets = _buckets; - var prec = _prec; - if (buckets !== undefined) { - var cell_next = buckets.next; - if (eq$1(buckets.key, key$2)) { - if (prec !== undefined) { - prec.next = cell_next; +function remove(h, key) { + var h_buckets = h.buckets; + var i = h.hash(key) & (h_buckets.length - 1 | 0); + var bucket = h_buckets[i]; + if (bucket !== undefined) { + var eq = h.eq; + if (eq(bucket.key, key)) { + h_buckets[i] = bucket.next; + h.size = h.size - 1 | 0; + return /* () */0; + } else { + var h$1 = h; + var key$1 = key; + var _prec = bucket; + var _bucket = bucket.next; + var eq$1 = eq; + while(true) { + var bucket$1 = _bucket; + var prec = _prec; + if (bucket$1 !== undefined) { + var cell_next = bucket$1.next; + if (eq$1(bucket$1.key, key$1)) { + prec.next = cell_next; + h$1.size = h$1.size - 1 | 0; + return /* () */0; + } else { + _bucket = cell_next; + _prec = bucket$1; + continue ; + + } } else { - h_buckets$1[i$1] = cell_next; + return /* () */0; } - h$2.size = h$2.size - 1 | 0; - } - _buckets = cell_next; - _prec = buckets; - continue ; - - } else { - return /* () */0; + }; } - }; + } else { + return /* () */0; + } } function get(h, key) { - var hash = h.hash; - var eq = h.eq; - var h$1 = h; - var key$1 = key; - var h_buckets = h$1.buckets; - var nid = hash(key$1) & (h_buckets.length - 1 | 0); + var h_buckets = h.buckets; + var nid = h.hash(key) & (h_buckets.length - 1 | 0); var match = h_buckets[nid]; if (match !== undefined) { - if (eq(key$1, match.key)) { + var eq = h.eq; + if (eq(key, match.key)) { return /* Some */[match.value]; } else { var match$1 = match.next; if (match$1 !== undefined) { - if (eq(key$1, match$1.key)) { + if (eq(key, match$1.key)) { return /* Some */[match$1.value]; } else { var match$2 = match$1.next; if (match$2 !== undefined) { - if (eq(key$1, match$2.key)) { + if (eq(key, match$2.key)) { return /* Some */[match$2.value]; } else { var eq$1 = eq; - var key$2 = key$1; + var key$1 = key; var _buckets = match$2.next; while(true) { var buckets = _buckets; if (buckets !== undefined) { - if (eq$1(key$2, buckets.key)) { + if (eq$1(key$1, buckets.key)) { return /* Some */[buckets.value]; } else { _buckets = buckets.next; @@ -227,76 +196,17 @@ function get(h, key) { } } -function getAll(h, key) { - var hash = h.hash; - var eq = h.eq; - var h$1 = h; - var key$1 = key; - var find_in_bucket = function (_buckets) { - while(true) { - var buckets = _buckets; - if (buckets !== undefined) { - if (eq(buckets.key, key$1)) { - return /* :: */[ - buckets.value, - find_in_bucket(buckets.next) - ]; - } else { - _buckets = buckets.next; - continue ; - - } - } else { - return /* [] */0; - } - }; - }; - var h_buckets = h$1.buckets; - var nid = hash(key$1) & (h_buckets.length - 1 | 0); - return find_in_bucket(h_buckets[nid]); -} - -function replace(h, key, info) { - var hash = h.hash; - var eq = h.eq; - var h$1 = h; - var key$1 = key; - var info$1 = info; - var h_buckets = h$1.buckets; - var i = hash(key$1) & (h_buckets.length - 1 | 0); - var l = h_buckets[i]; - if (replace_bucket(eq, key$1, info$1, l)) { - h_buckets[i] = { - key: key$1, - value: info$1, - next: l - }; - h$1.size = h$1.size + 1 | 0; - if (h$1.size > (h$1.buckets.length << 1)) { - return resize(hash, h$1); - } else { - return 0; - } - } else { - return 0; - } -} - function has(h, key) { - var hash = h.hash; - var eq = h.eq; - var h$1 = h; - var key$1 = key; - var h_buckets = h$1.buckets; - var nid = hash(key$1) & (h_buckets.length - 1 | 0); + var h_buckets = h.buckets; + var nid = h.hash(key) & (h_buckets.length - 1 | 0); var bucket = h_buckets[nid]; if (bucket !== undefined) { - var eq$1 = eq; - var key$2 = key$1; + var key$1 = key; var _cell = bucket; + var eq = h.eq; while(true) { var cell = _cell; - if (eq$1(cell.key, key$2)) { + if (eq(cell.key, key$1)) { return /* true */1; } else { var match = cell.next; @@ -314,28 +224,96 @@ function has(h, key) { } } +function make(initialize_size, dict) { + return Bs_internalBucketsType.make(dict[/* hash */0], dict[/* eq */1], initialize_size); +} + +function add0(h, key, value, hash) { + var h_buckets = h.buckets; + var buckets_lenth = h_buckets.length; + var i = hash(key) & (buckets_lenth - 1 | 0); + var bucket = { + key: key, + value: value, + next: h_buckets[i] + }; + h_buckets[i] = bucket; + var h_new_size = h.size + 1 | 0; + h.size = h_new_size; + if (h_new_size > (buckets_lenth << 1)) { + return resize(hash, h); + } else { + return 0; + } +} + +function add(h, key, info) { + return add0(h, key, info, h.hash); +} + +function ofArray(arr, dict) { + var hash = dict[/* hash */0]; + var eq = dict[/* eq */1]; + var len = arr.length; + var v = Bs_internalBucketsType.make(hash, eq, len); + for(var i = 0 ,i_finish = len - 1 | 0; i <= i_finish; ++i){ + var match = arr[i]; + add0(v, match[0], match[1], hash); + } + return v; +} + +function mergeMany(h, arr) { + var hash = h.hash; + var len = arr.length; + for(var i = 0 ,i_finish = len - 1 | 0; i <= i_finish; ++i){ + var match = arr[i]; + add0(h, match[0], match[1], hash); + } + return /* () */0; +} + var clear = Bs_internalBucketsType.clear; +var isEmpty = Bs_internalBucketsType.isEmpty; + +var copy = Bs_internalBuckets.copy; + var forEach = Bs_internalBuckets.forEach; var reduce = Bs_internalBuckets.reduce; var keepMapInPlace = Bs_internalBuckets.keepMapInPlace; +var toArray = Bs_internalBuckets.toArray; + +var keysToArray = Bs_internalBuckets.keysToArray; + +var valuesToArray = Bs_internalBuckets.valuesToArray; + +var getBucketHistogram = Bs_internalBuckets.getBucketHistogram; + var logStats = Bs_internalBuckets.logStats; exports.make = make; exports.clear = clear; +exports.isEmpty = isEmpty; exports.add = add; +exports.replace = replace; +exports.replaceBy = replaceBy; +exports.copy = copy; exports.get = get; -exports.getAll = getAll; exports.has = has; exports.remove = remove; -exports.removeAll = removeAll; -exports.replace = replace; exports.forEach = forEach; exports.reduce = reduce; exports.keepMapInPlace = keepMapInPlace; exports.size = size; +exports.toArray = toArray; +exports.keysToArray = keysToArray; +exports.valuesToArray = valuesToArray; +exports.ofArray = ofArray; +exports.mergeMany = mergeMany; +exports.getBucketHistogram = getBucketHistogram; exports.logStats = logStats; /* No side effect */ From 8812983b10f794e7dda92c92d488a862169db9cd Mon Sep 17 00:00:00 2001 From: Hongbo Zhang Date: Thu, 1 Feb 2018 11:16:12 +0800 Subject: [PATCH 2/6] remove bs_HashMultiMap --- jscomp/others/.depend | 3 - jscomp/others/Makefile | 1 - jscomp/others/bs.ml | 3 - jscomp/others/bs_HashMultiMap.ml | 258 ------------------------------ jscomp/others/bs_HashMultiMap.mli | 107 ------------- 5 files changed, 372 deletions(-) delete mode 100644 jscomp/others/bs_HashMultiMap.ml delete mode 100644 jscomp/others/bs_HashMultiMap.mli diff --git a/jscomp/others/.depend b/jscomp/others/.depend index b9e52a052c..7a3b955f1c 100644 --- a/jscomp/others/.depend +++ b/jscomp/others/.depend @@ -38,8 +38,6 @@ bs_internalBuckets.cmj : bs_internalBucketsType.cmj bs_Array.cmj \ bs_HashMap.cmj : bs_internalBucketsType.cmj bs_internalBuckets.cmj \ bs_HashMapString.cmj bs_HashMapInt.cmj bs_Dict.cmj bs_Array.cmj \ bs_HashMap.cmi -bs_HashMultiMap.cmj : bs_internalBucketsType.cmj bs_internalBuckets.cmj \ - bs_Dict.cmj bs_Array.cmj bs_HashMultiMap.cmi bs_HashSet.cmj : bs_internalSetBuckets.cmj bs_internalBucketsType.cmj \ bs_HashSetString.cmj bs_HashSetInt.cmj bs_Dict.cmj bs_Array.cmj \ bs_HashSet.cmi @@ -120,7 +118,6 @@ bs_internalBucketsType.cmi : bs_internalSetBuckets.cmi : bs_internalBucketsType.cmi bs_internalBuckets.cmi : bs_internalBucketsType.cmi bs_HashMap.cmi : bs_HashMapString.cmi bs_HashMapInt.cmi bs_Dict.cmi -bs_HashMultiMap.cmi : bs_Dict.cmi bs_HashSet.cmi : bs_HashSetString.cmi bs_HashSetInt.cmi bs_Dict.cmi bs_HashSetString.cmi : bs_HashSetInt.cmi : diff --git a/jscomp/others/Makefile b/jscomp/others/Makefile index 63fe1d682d..76e0a91930 100644 --- a/jscomp/others/Makefile +++ b/jscomp/others/Makefile @@ -25,7 +25,6 @@ SOURCE_LIST= node_path node_fs node_process dict node_module js_array js_string bs_internalSetBuckets\ bs_internalBuckets\ bs_HashMap\ - bs_HashMultiMap\ bs_HashSet\ bs_HashSetString\ bs_HashSetInt\ diff --git a/jscomp/others/bs.ml b/jscomp/others/bs.ml index 84e6eca3a0..a861299e59 100644 --- a/jscomp/others/bs.ml +++ b/jscomp/others/bs.ml @@ -106,6 +106,3 @@ module SortArrayInt = Bs_SortArrayInt module SortArrayString = Bs_SortArrayString - - -(* module HashMultiMap = Bs_HashMultiMap *) diff --git a/jscomp/others/bs_HashMultiMap.ml b/jscomp/others/bs_HashMultiMap.ml deleted file mode 100644 index 3f3166fb65..0000000000 --- a/jscomp/others/bs_HashMultiMap.ml +++ /dev/null @@ -1,258 +0,0 @@ -(***********************************************************************) -(* *) -(* OCaml *) -(* *) -(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) -(* *) -(* Copyright 1996 Institut National de Recherche en Informatique et *) -(* en Automatique. All rights reserved. This file is distributed *) -(* under the terms of the GNU Library General Public License, with *) -(* the special exception on linking described in file ../LICENSE. *) -(* *) -(***********************************************************************) -(** Adapted by Authors of BuckleScript 2017 *) - -module N = Bs_internalBuckets -module C = Bs_internalBucketsType -module A = Bs_Array - -type ('a, 'id) eq = ('a, 'id) Bs_Dict.eq -type ('a, 'id) hash = ('a, 'id) Bs_Dict.hash -type ('a, 'id) dict = ('a, 'id) Bs_Dict.hashable - -type ('a, 'b,'id) t = ( ('a, 'id) hash, ('a, 'id) eq , 'a,'b) N.t - -let clear = C.clear -let size = C.size -let forEach = N.forEach -let reduce = N.reduce -let logStats = N.logStats -let keepMapInPlace = N.keepMapInPlace -let toArray = N.toArray -let copy = N.copy -let keysToArray = N.keysToArray -let valuesToArray = N.valuesToArray -let getBucketHistogram = N.getBucketHistogram -let isEmpty = C.isEmpty - - -let rec copyBucketReHash ~hash ~h_buckets ~ndata_tail old_bucket = - match C.toOpt old_bucket with - | None -> () - | Some cell -> - let nidx = hash (N.key cell) [@bs] land (A.length h_buckets - 1) in - let v = C.return cell in - begin match C.toOpt (A.getUnsafe ndata_tail nidx) with - | None -> - A.setUnsafe h_buckets nidx v - | Some tail -> - N.nextSet tail v (* cell put at the end *) - end; - A.setUnsafe ndata_tail nidx v; - copyBucketReHash ~hash ~h_buckets ~ndata_tail (N.next cell) - - -let resize ~hash h = - let odata = C.buckets h in - let osize = A.length odata in - let nsize = osize * 2 in - if nsize >= osize then begin (* no overflow *) - 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 - copyBucketReHash ~hash ~h_buckets ~ndata_tail (A.getUnsafe odata i) - done; - for i = 0 to nsize - 1 do - match C.toOpt (A.getUnsafe ndata_tail i) with - | None -> () - | Some tail -> N.nextSet tail C.emptyOpt - done - end - -let rec replaceFirst ~eq key info cell = - if eq (N.key cell) key [@bs] - then - begin - N.valueSet cell info; - false - end - else - match C.toOpt (N.next cell) with - | None -> true - | Some cell -> - replaceFirst ~eq key info cell - -(* - Since we are replacing the first one in the bucket, - it requires when adding new element, the newer comes in - the head, so that replace will replace the latest one - [add tbl 10 '0'; add tbl 10 '1'] - the replacement will replace [10,'1'] -*) -let replaceBy h key value ~eq ~hash = - let h_buckets = C.buckets h in - let buckets_len = A.length h_buckets in - let hash, eq = Bs_Dict.getHashInternal hash , Bs_Dict.getEqInternal eq in - let i = hash key [@bs] land (buckets_len - 1) in - let l = A.getUnsafe h_buckets i in - (match C.toOpt l with - | None -> - A.setUnsafe h_buckets i (C.return (N.bucket ~key ~value ~next:C.emptyOpt)); - C.sizeSet h (C.size h + 1); - | Some bucket -> - if replaceFirst ~eq key value bucket then begin - A.setUnsafe h_buckets i (C.return (N.bucket ~key ~value ~next:l)); - C.sizeSet h (C.size h + 1); - end - ); - if C.size h > buckets_len lsl 1 then resize ~hash h - -let replace h key value = - replaceBy h key value ~eq:(C.eq h) ~hash:(C.hash h) - -let rec removeInBucket h h_buckets i key prec bucket ~eq = - match C.toOpt bucket with - | None -> () - | Some cell -> - let cell_next = N.next cell in - if eq (N.key cell) key [@bs] - then - begin - N.nextSet prec cell_next ; - C.sizeSet h (C.size h - 1); - end - else removeInBucket ~eq h h_buckets i key cell cell_next - - -let remove h key = - let h_buckets = C.buckets h in - let i = (Bs_Dict.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in - let bucket = (A.getUnsafe h_buckets i) in - match C.toOpt bucket with - | None -> () - | Some cell -> - let eq = (Bs_Dict.getEqInternal (C.eq h)) in - if eq (N.key cell ) key [@bs] then - begin - A.setUnsafe h_buckets i (N.next cell); - C.sizeSet h (C.size h - 1) - end - else - removeInBucket ~eq h h_buckets i key cell (N.next cell) - -(* TODO: add [removeAll] *) - - -let rec getAux ~eq key buckets = - match C.toOpt buckets with - | None -> - None - | Some cell -> - if eq key (N.key cell) [@bs] then Some (N.value cell) - else getAux ~eq key (N.next cell) - -let get h key = - let h_buckets = C.buckets h in - let nid = (Bs_Dict.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in - match C.toOpt @@ A.getUnsafe h_buckets nid with - | None -> None - | Some cell1 -> - let eq = Bs_Dict.getEqInternal (C.eq h) in - if eq key (N.key cell1) [@bs] then - Some (N.value cell1) - else - match C.toOpt (N.next cell1) with - | None -> None - | Some cell2 -> - if eq key (N.key cell2) [@bs] then - Some (N.value cell2) else - match C.toOpt (N.next cell2) with - | None -> None - | Some cell3 -> - if eq key (N.key cell3) [@bs] then - Some (N.value cell3) - else - getAux ~eq key (N.next cell3) - -(*TODO: getAll stack-safe *) -(* let rec findAlInBucket buckets key ~eq = - match C.toOpt buckets with - | None -> - [] - | Some cell -> - if eq (N.key cell) key [@bs] - then (N.value cell) :: findAlInBucket (N.next cell) - else findAlInBucket (N.next cell) - -let getAll0 ~hash ~eq h key = - let h_buckets = C.buckets h in - let nid = (Bs_Dict.getHashInternal hash) key [@bs] land (A.length h_buckets - 1) in - findAlInBucket (A.getUnsafe h_buckets nid) - - -let getAll h key = - getAll0 ~hash:(C.hash h) ~eq:(C.eq h) h key - *) - - -let rec memInBucket key cell ~eq = - eq (N.key cell) key [@bs] || - (match C.toOpt (N.next cell) with - | None -> false - | Some nextCell -> - memInBucket ~eq key nextCell) - -let has h key = - let h_buckets = C.buckets h in - let nid = (Bs_Dict.getHashInternal (C.hash h)) key [@bs] land (A.length h_buckets - 1) in - let bucket = (A.getUnsafe h_buckets nid) in - match C.toOpt bucket with - | None -> false - | Some bucket -> - memInBucket ~eq:(Bs_Dict.getEqInternal (C.eq h)) key bucket - - - -let make (type elt) (type id) initialize_size ~(dict : (elt, id) dict) = - let module M = (val dict) in - C.make initialize_size ~hash:M.hash ~eq:M.eq - - -(****************************************************************************) - -let add0 h key value ~hash = - let h_buckets = C.buckets h in - let buckets_lenth = A.length h_buckets in - let i = hash key [@bs] land (buckets_lenth - 1) in - let bucket = - N.bucket ~key ~value ~next:(A.getUnsafe h_buckets i) in - A.setUnsafe 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 > buckets_lenth lsl 1 then resize ~hash h - - -let add h key info = - add0 ~hash:(Bs_Dict.getHashInternal (C.hash h)) h key info - -let ofArray (type a) (type id) arr ~dict:(dict:(a,id) dict) = - let module M = (val dict) in - let hash, eq = M.hash, M.eq in - let len = A.length arr in - let v = C.make ~hash ~eq len in - let hash = Bs_Dict.getHashInternal hash in - for i = 0 to len - 1 do - let key,value = (A.getUnsafe arr i) in - add0 ~hash v key value - done ; - v - -let mergeMany h arr = - let hash = Bs_Dict.getHashInternal ( C.hash h) in - let len = A.length arr in - for i = 0 to len - 1 do - let key,value = (A.getUnsafe arr i) in - add0 h ~hash key value - done - \ No newline at end of file diff --git a/jscomp/others/bs_HashMultiMap.mli b/jscomp/others/bs_HashMultiMap.mli deleted file mode 100644 index 99bc177235..0000000000 --- a/jscomp/others/bs_HashMultiMap.mli +++ /dev/null @@ -1,107 +0,0 @@ - - - - -type ('key,'value,'id) t - -(** The type of hash tables from type ['a] to type ['b]. *) - -type ('a, 'id) eq = ('a, 'id) Bs_Dict.eq -type ('a, 'id) hash = ('a, 'id) Bs_Dict.hash -type ('a, 'id) dict = ('a, 'id) Bs_Dict.hashable - -val make : int -> dict: ('a, 'id) dict -> ('a,'b,'id) t -(** [make n ~dict] creates a new, empty hash table, with - initial size [n]. For best results, [n] should be on the - order of the expected number of elements that will be in - the table. The table grows as needed, so [n] is just an - initial guess. -*) - - -val clear : ('a, 'b, 'id) t -> unit -(** Empty a hash table. *) - -val isEmpty: _ t -> bool - - -val add: ('a, 'b, 'id) t -> 'a -> 'b -> unit -(** [add tbl x y] adds a binding of [x] to [y] in table [tbl]. - Previous bindings for [x] are not removed, but simply - hidden. That is, after performing [remove tbl x], - the previous binding for [x], if any, is restored. - (Same behavior as with association lists.) *) - - val replace: ('a, 'b, 'id) t -> 'a -> 'b -> unit -(** [replace tbl x y] replaces the current binding of [x] - in [tbl] by a binding of [x] to [y]. If [x] is unbound in [tbl], - a binding of [x] to [y] is added to [tbl]. - This is functionally equivalent to [remove tbl x] - followed by [add tbl x y]. *) - -val replaceBy: - ('key, 'value, 'id) t -> - 'key -> - 'value -> - eq:('key,'id) eq -> - hash:('key,'id) hash -> - unit -(** [replaceBy tbl k v ~eq ~hash] the same as - [replace tbl k v] except that [eq] and [hash] - is supplied directly so it can be batched (slightly faster) -*) - -val copy: ('key, 'value, 'id) t -> ('key, 'value, 'id) t - -val get: ('key, 'value, 'id) t -> 'key -> 'value option - - -val has: ('key, 'value, 'id) t -> 'key -> bool -(** [has tbl x] checks if [x] is bound in [tbl]. *) - - -val remove: ('key, 'value, 'id) t -> 'key -> unit -(** [remove tbl x] removes the current binding of [x] in [tbl], - restoring the previous binding if it exists. - It does nothing if [x] is not bound in [tbl]. *) - -val forEach : ('a, 'b, 'id) t -> ('a -> 'b -> unit [@bs]) -> unit -(** [forEach f tbl] applies [f] to all bindings in table [tbl]. - [f] receives the key as first argument, and the associated value - as second argument. Each binding is presented exactly once to [f]. -*) - - -val reduce : ('a, 'b, 'id) t -> 'c -> ('c -> 'a -> 'b -> 'c [@bs]) -> 'c -(** [reduce f tbl init] computes - [(f kN dN ... (f k1 d1 init)...)], - where [k1 ... kN] are the keys of all bindings in [tbl], - and [d1 ... dN] are the associated values. - Each binding is presented exactly once to [f]. - - The order in which the bindings are passed to [f] is unspecified. - However, if the table contains several bindings for the same key, - they are passed to [f] in reverse order of introduction, that is, - the most recent binding is passed first. -*) - - -val keepMapInPlace : ('a, 'b, 'id) t -> ('a -> 'b -> 'b option [@bs]) -> unit - -val size : _ t -> int -(** [size tbl] returns the number of bindings in [tbl]. - It takes constant time. Multiple bindings are counted once each, so - [size] gives the number of times [forEach] calls its - first argument. *) - - - -val toArray: ('key, 'value, 'id ) t -> ('key * 'value) array -val keysToArray: ('key, _, _) t -> 'key array -val valuesToArray: (_,'value,_) t -> 'value array -val ofArray: ('key * 'value) array -> dict:('key,'id) dict -> ('key, 'value, 'id ) t -val mergeMany: ('key, 'value, 'id ) t -> ('key * 'value) array -> unit -val getBucketHistogram: _ t -> int array -val logStats: _ t -> unit -val logStats : _ t -> unit - From deb550cb22336a9aceb273613fcc689bd09ef390 Mon Sep 17 00:00:00 2001 From: Hongbo Zhang Date: Thu, 1 Feb 2018 11:34:40 +0800 Subject: [PATCH 3/6] using make , add clear --- jscomp/others/bs_Array.ml | 3 ++- jscomp/others/bs_Array.mli | 4 ++-- jscomp/others/bs_List.ml | 3 ++- jscomp/others/bs_List.mli | 4 +++- jscomp/others/bs_Map.ml | 2 +- jscomp/others/bs_Map.mli | 2 +- jscomp/others/bs_MapIntM.ml | 3 ++- jscomp/others/bs_MapIntM.mli | 3 ++- jscomp/others/bs_MapM.ml | 4 +++- jscomp/others/bs_MapM.mli | 3 ++- jscomp/others/bs_MapStringM.ml | 3 ++- jscomp/others/bs_MapStringM.mli | 3 ++- jscomp/others/bs_Set.ml | 2 +- jscomp/others/bs_Set.mli | 2 +- jscomp/others/bs_SetIntM.ml | 10 +++++----- jscomp/others/bs_SetIntM.mli | 2 +- jscomp/others/bs_SetM.ml | 2 +- jscomp/others/bs_SetM.mli | 2 +- jscomp/others/bs_SetStringM.ml | 10 +++++----- jscomp/others/bs_SetStringM.mli | 2 +- jscomp/others/mapm.cppo.ml | 3 ++- jscomp/others/mapm.cppo.mli | 3 ++- jscomp/others/setm.cppo.ml | 10 +++++----- jscomp/others/setm.cppo.mli | 2 +- lib/js/bs_Array.js | 2 +- lib/js/bs_List.js | 3 +++ lib/js/bs_Map.js | 4 ++-- lib/js/bs_MapIntM.js | 10 ++++++++-- lib/js/bs_MapM.js | 10 ++++++++-- lib/js/bs_MapStringM.js | 10 ++++++++-- lib/js/bs_Set.js | 4 ++-- lib/js/bs_SetIntM.js | 4 ++-- lib/js/bs_SetM.js | 4 ++-- lib/js/bs_SetStringM.js | 4 ++-- 34 files changed, 88 insertions(+), 54 deletions(-) diff --git a/jscomp/others/bs_Array.ml b/jscomp/others/bs_Array.ml index 218efddcc8..1a1e979ec4 100644 --- a/jscomp/others/bs_Array.ml +++ b/jscomp/others/bs_Array.ml @@ -13,7 +13,8 @@ (* Array operations *) -external length : 'a array -> int = "%array_length" +external length: 'a array -> int = "%array_length" +external size: 'a array -> int = "%array_length" external getUnsafe: 'a array -> int -> 'a = "%array_unsafe_get" external setUnsafe: 'a array -> int -> 'a -> unit = "%array_unsafe_set" external getUndefined: 'a array -> int -> 'a Js.undefined = "%array_unsafe_get" diff --git a/jscomp/others/bs_Array.mli b/jscomp/others/bs_Array.mli index 820d50dc90..eab576b47f 100644 --- a/jscomp/others/bs_Array.mli +++ b/jscomp/others/bs_Array.mli @@ -12,8 +12,8 @@ (***********************************************************************) -external length : 'a array -> int = "%array_length" - +external length: 'a array -> int = "%array_length" +external size: 'a array -> int = "%array_length" val get : 'a array -> int -> 'a option val set : 'a array -> int -> 'a -> unit diff --git a/jscomp/others/bs_List.ml b/jscomp/others/bs_List.ml index 964ca189cf..35f596dd82 100644 --- a/jscomp/others/bs_List.ml +++ b/jscomp/others/bs_List.ml @@ -368,7 +368,8 @@ let rec lengthAux x acc = | _::t -> lengthAux t (acc + 1) let length xs = lengthAux xs 0 - +let size = length + let rec fillAux arr i x = match x with | [] -> () diff --git a/jscomp/others/bs_List.mli b/jscomp/others/bs_List.mli index eb8ee765aa..633c409095 100644 --- a/jscomp/others/bs_List.mli +++ b/jscomp/others/bs_List.mli @@ -54,7 +54,9 @@ val zipBy: 'a t -> 'b t -> ('a -> 'b -> 'c [@bs]) -> 'c t val mapWithIndex: 'a t -> (int -> 'a -> 'b [@bs]) -> 'b t val length: 'a t -> int - +val size: 'a t -> int +(** [size l] is the same as [lenth l] *) + val toArray: 'a t -> 'a array (* type json = Js_json.t *) diff --git a/jscomp/others/bs_Map.ml b/jscomp/others/bs_Map.ml index d2ea4241ec..8cff8a2bc1 100644 --- a/jscomp/others/bs_Map.ml +++ b/jscomp/others/bs_Map.ml @@ -65,7 +65,7 @@ let merge s1 s2 f = let cmp = S.cmp s1 in S.t ~cmp ~data:(N.merge ~cmp (S.data s1) (S.data s2) f) -let empty (type elt) (type id) ~(dict: (elt, id) dict) = +let make (type elt) (type id) ~(dict: (elt, id) dict) = let module M = (val dict) in S.t ~cmp:M.cmp ~data:N.empty diff --git a/jscomp/others/bs_Map.mli b/jscomp/others/bs_Map.mli index ff8094a145..abdb191ec7 100644 --- a/jscomp/others/bs_Map.mli +++ b/jscomp/others/bs_Map.mli @@ -40,7 +40,7 @@ type ('key, 'id ) dict = ('key, 'id) Bs_Dict.comparable (* should not export [Bs_Dict.compare]. should only export [Bs_Dict.t] or [Bs_Dict.cmp] instead *) -val empty: dict:('k, 'id) dict -> ('k, 'a, 'id) t +val make: dict:('k, 'id) dict -> ('k, 'a, 'id) t val isEmpty: _ t -> bool val has: ('k, 'a, 'id) t -> 'k -> bool diff --git a/jscomp/others/bs_MapIntM.ml b/jscomp/others/bs_MapIntM.ml index eb42524486..3971476508 100644 --- a/jscomp/others/bs_MapIntM.ml +++ b/jscomp/others/bs_MapIntM.ml @@ -13,8 +13,9 @@ type 'a t = { } [@@bs.deriving abstract] -let empty () = t ~data:N.empty +let make () = t ~data:N.empty let isEmpty m = N.isEmpty (data m) +let clear m = dataSet m N.empty let singleton k v = t ~data:(N.singleton k v) let minKeyUndefined m = N.minKeyUndefined (data m) diff --git a/jscomp/others/bs_MapIntM.mli b/jscomp/others/bs_MapIntM.mli index b8fd0dfefb..9f5e822632 100644 --- a/jscomp/others/bs_MapIntM.mli +++ b/jscomp/others/bs_MapIntM.mli @@ -29,7 +29,8 @@ type key = int type 'a t -val empty: unit -> 'a t +val make: unit -> 'a t +val clear: 'a t -> unit val isEmpty: 'a t -> bool val has: 'a t -> key -> bool diff --git a/jscomp/others/bs_MapM.ml b/jscomp/others/bs_MapM.ml index ae41c6e4ea..089382d678 100644 --- a/jscomp/others/bs_MapM.ml +++ b/jscomp/others/bs_MapM.ml @@ -139,9 +139,11 @@ let update t x f = if newRoot != oldRoot then S.dataSet t newRoot -let empty (type elt) (type id) ~(dict : (elt,id) dict) = +let make (type elt) (type id) ~(dict : (elt,id) dict) = let module M = (val dict) in S.t ~cmp:M.cmp ~data:N.empty + +let clear m = S.dataSet m N.empty let isEmpty d = N.isEmpty (S.data d) diff --git a/jscomp/others/bs_MapM.mli b/jscomp/others/bs_MapM.mli index 59b4e2e0c3..56f6f3918c 100644 --- a/jscomp/others/bs_MapM.mli +++ b/jscomp/others/bs_MapM.mli @@ -26,7 +26,8 @@ type ('k,'v,'id) t type ('key, 'id) dict = ('key, 'id) Bs_Dict.comparable -val empty: dict:('k, 'id) dict -> ('k, 'a, 'id) t +val make: dict:('k, 'id) dict -> ('k, 'a, 'id) t +val clear: _ t -> unit val isEmpty: _ t -> bool val has: ('k, _, _) t -> 'k -> bool val cmp: diff --git a/jscomp/others/bs_MapStringM.ml b/jscomp/others/bs_MapStringM.ml index d7ac2c950d..34727ab756 100644 --- a/jscomp/others/bs_MapStringM.ml +++ b/jscomp/others/bs_MapStringM.ml @@ -13,8 +13,9 @@ type 'a t = { } [@@bs.deriving abstract] -let empty () = t ~data:N.empty +let make () = t ~data:N.empty let isEmpty m = N.isEmpty (data m) +let clear m = dataSet m N.empty let singleton k v = t ~data:(N.singleton k v) let minKeyUndefined m = N.minKeyUndefined (data m) diff --git a/jscomp/others/bs_MapStringM.mli b/jscomp/others/bs_MapStringM.mli index 61e1cdf9ca..a7daeaeca1 100644 --- a/jscomp/others/bs_MapStringM.mli +++ b/jscomp/others/bs_MapStringM.mli @@ -29,7 +29,8 @@ type key = string type 'a t -val empty: unit -> 'a t +val make: unit -> 'a t +val clear: 'a t -> unit val isEmpty: 'a t -> bool val has: 'a t -> key -> bool diff --git a/jscomp/others/bs_Set.ml b/jscomp/others/bs_Set.ml index f09a59f317..a817719577 100644 --- a/jscomp/others/bs_Set.ml +++ b/jscomp/others/bs_Set.ml @@ -85,7 +85,7 @@ let split m e = let (l, r), b = N.split ~cmp (S.data m) e in (S.t ~cmp ~data:l, S.t ~cmp ~data:r), b -let empty (type elt) (type id) ~(dict : (elt, id) dict) = +let make (type elt) (type id) ~(dict : (elt, id) dict) = let module M = (val dict) in S.t ~cmp:M.cmp ~data:N.empty diff --git a/jscomp/others/bs_Set.mli b/jscomp/others/bs_Set.mli index 6270895a27..20bd092a52 100644 --- a/jscomp/others/bs_Set.mli +++ b/jscomp/others/bs_Set.mli @@ -29,7 +29,7 @@ type ('k,'id) t type ('key, 'id) dict = ('key, 'id) Bs_Dict.comparable -val empty: dict:('elt, 'id) dict -> ('elt, 'id) t +val make: dict:('elt, 'id) dict -> ('elt, 'id) t val ofArray: 'k array -> dict:('k, 'id) dict -> ('k, 'id) t diff --git a/jscomp/others/bs_SetIntM.ml b/jscomp/others/bs_SetIntM.ml index 4e0febbe25..12bd872dcd 100644 --- a/jscomp/others/bs_SetIntM.ml +++ b/jscomp/others/bs_SetIntM.ml @@ -153,7 +153,7 @@ let mergeMany d arr = -let empty () = t ~data:N.empty +let make () = t ~data:N.empty let isEmpty d = N.isEmpty (data d) @@ -238,8 +238,8 @@ let subset a b = I.subset (data a) (data b) let intersect dataa datab = let dataa, datab = data dataa, data datab in match N.toOpt dataa, N.toOpt datab with - | None, _ -> empty () - | _, None -> empty () + | None, _ -> make () + | _, None -> make () | Some dataa0, Some datab0 -> let sizea, sizeb = N.lengthNode dataa0, N.lengthNode datab0 in @@ -254,7 +254,7 @@ let intersect dataa datab = (A.getUnsafe tmp (totalSize - 1) < A.getUnsafe tmp 0) ) - then empty () + then make () else let tmp2 = A.makeUninitializedUnsafe (min sizea sizeb) in let k = S.intersect tmp 0 sizea tmp sizea sizeb tmp2 0 in @@ -263,7 +263,7 @@ let intersect dataa datab = let diff dataa datab : t = let dataa, datab = data dataa, data datab in match N.toOpt dataa, N.toOpt datab with - | None, _ -> empty () + | None, _ -> make () | _, None -> t ~data:(N.copy dataa) | Some dataa0, Some datab0 -> let sizea, sizeb = N.lengthNode dataa0, N.lengthNode datab0 in diff --git a/jscomp/others/bs_SetIntM.mli b/jscomp/others/bs_SetIntM.mli index 2685b98e10..8bd24ae7f8 100644 --- a/jscomp/others/bs_SetIntM.mli +++ b/jscomp/others/bs_SetIntM.mli @@ -28,7 +28,7 @@ type elt = int # 33 type t -val empty: unit -> t +val make: unit -> t val ofArray: elt array -> t val ofSortedArrayUnsafe: elt array -> t diff --git a/jscomp/others/bs_SetM.ml b/jscomp/others/bs_SetM.ml index 34f98e6371..3f3dcb2cff 100644 --- a/jscomp/others/bs_SetM.ml +++ b/jscomp/others/bs_SetM.ml @@ -187,7 +187,7 @@ let mergeMany d xs = S.dataSet d (addArrayMutate (S.data d) xs ~cmp:(S.cmp d)) -let empty (type elt) (type id) ~(dict : (elt, id) dict) = +let make (type elt) (type id) ~(dict : (elt, id) dict) = let module M = (val dict) in S.t ~cmp:M.cmp ~data:N.empty diff --git a/jscomp/others/bs_SetM.mli b/jscomp/others/bs_SetM.mli index 9664841cf2..2608343b14 100644 --- a/jscomp/others/bs_SetM.mli +++ b/jscomp/others/bs_SetM.mli @@ -27,7 +27,7 @@ type ('k,'id) t type ('k, 'id) dict = ('k, 'id) Bs_Dict.comparable -val empty: dict:('elt, 'id) dict -> ('elt, 'id) t +val make: dict:('elt, 'id) dict -> ('elt, 'id) t val ofArray: 'k array -> dict:('k, 'id) dict -> ('k, 'id) t val ofSortedArrayUnsafe: 'elt array -> dict:('elt, 'id) dict -> ('elt,'id) t diff --git a/jscomp/others/bs_SetStringM.ml b/jscomp/others/bs_SetStringM.ml index 8beedde116..b3cbbf10fa 100644 --- a/jscomp/others/bs_SetStringM.ml +++ b/jscomp/others/bs_SetStringM.ml @@ -153,7 +153,7 @@ let mergeMany d arr = -let empty () = t ~data:N.empty +let make () = t ~data:N.empty let isEmpty d = N.isEmpty (data d) @@ -238,8 +238,8 @@ let subset a b = I.subset (data a) (data b) let intersect dataa datab = let dataa, datab = data dataa, data datab in match N.toOpt dataa, N.toOpt datab with - | None, _ -> empty () - | _, None -> empty () + | None, _ -> make () + | _, None -> make () | Some dataa0, Some datab0 -> let sizea, sizeb = N.lengthNode dataa0, N.lengthNode datab0 in @@ -254,7 +254,7 @@ let intersect dataa datab = (A.getUnsafe tmp (totalSize - 1) < A.getUnsafe tmp 0) ) - then empty () + then make () else let tmp2 = A.makeUninitializedUnsafe (min sizea sizeb) in let k = S.intersect tmp 0 sizea tmp sizea sizeb tmp2 0 in @@ -263,7 +263,7 @@ let intersect dataa datab = let diff dataa datab : t = let dataa, datab = data dataa, data datab in match N.toOpt dataa, N.toOpt datab with - | None, _ -> empty () + | None, _ -> make () | _, None -> t ~data:(N.copy dataa) | Some dataa0, Some datab0 -> let sizea, sizeb = N.lengthNode dataa0, N.lengthNode datab0 in diff --git a/jscomp/others/bs_SetStringM.mli b/jscomp/others/bs_SetStringM.mli index 502b1e6078..58a5fa19cd 100644 --- a/jscomp/others/bs_SetStringM.mli +++ b/jscomp/others/bs_SetStringM.mli @@ -28,7 +28,7 @@ type elt = string # 33 type t -val empty: unit -> t +val make: unit -> t val ofArray: elt array -> t val ofSortedArrayUnsafe: elt array -> t diff --git a/jscomp/others/mapm.cppo.ml b/jscomp/others/mapm.cppo.ml index eb776bbd49..5e9dee4e89 100644 --- a/jscomp/others/mapm.cppo.ml +++ b/jscomp/others/mapm.cppo.ml @@ -18,8 +18,9 @@ type 'a t = { } [@@bs.deriving abstract] -let empty () = t ~data:N.empty +let make () = t ~data:N.empty let isEmpty m = N.isEmpty (data m) +let clear m = dataSet m N.empty let singleton k v = t ~data:(N.singleton k v) let minKeyUndefined m = N.minKeyUndefined (data m) diff --git a/jscomp/others/mapm.cppo.mli b/jscomp/others/mapm.cppo.mli index ef2de393c5..8769ab51e4 100644 --- a/jscomp/others/mapm.cppo.mli +++ b/jscomp/others/mapm.cppo.mli @@ -32,7 +32,8 @@ type key = int type 'a t -val empty: unit -> 'a t +val make: unit -> 'a t +val clear: 'a t -> unit val isEmpty: 'a t -> bool val has: 'a t -> key -> bool diff --git a/jscomp/others/setm.cppo.ml b/jscomp/others/setm.cppo.ml index e6b5a6fac3..26121476f5 100644 --- a/jscomp/others/setm.cppo.ml +++ b/jscomp/others/setm.cppo.ml @@ -158,7 +158,7 @@ let mergeMany d arr = -let empty () = t ~data:N.empty +let make () = t ~data:N.empty let isEmpty d = N.isEmpty (data d) @@ -243,8 +243,8 @@ let subset a b = I.subset (data a) (data b) let intersect dataa datab = let dataa, datab = data dataa, data datab in match N.toOpt dataa, N.toOpt datab with - | None, _ -> empty () - | _, None -> empty () + | None, _ -> make () + | _, None -> make () | Some dataa0, Some datab0 -> let sizea, sizeb = N.lengthNode dataa0, N.lengthNode datab0 in @@ -259,7 +259,7 @@ let intersect dataa datab = (A.getUnsafe tmp (totalSize - 1) < A.getUnsafe tmp 0) ) - then empty () + then make () else let tmp2 = A.makeUninitializedUnsafe (min sizea sizeb) in let k = S.intersect tmp 0 sizea tmp sizea sizeb tmp2 0 in @@ -268,7 +268,7 @@ let intersect dataa datab = let diff dataa datab : t = let dataa, datab = data dataa, data datab in match N.toOpt dataa, N.toOpt datab with - | None, _ -> empty () + | None, _ -> make () | _, None -> t ~data:(N.copy dataa) | Some dataa0, Some datab0 -> let sizea, sizeb = N.lengthNode dataa0, N.lengthNode datab0 in diff --git a/jscomp/others/setm.cppo.mli b/jscomp/others/setm.cppo.mli index 8972f71044..1471f59c90 100644 --- a/jscomp/others/setm.cppo.mli +++ b/jscomp/others/setm.cppo.mli @@ -31,7 +31,7 @@ type elt = int #endif type t -val empty: unit -> t +val make: unit -> t val ofArray: elt array -> t val ofSortedArrayUnsafe: elt array -> t diff --git a/lib/js/bs_Array.js b/lib/js/bs_Array.js index a6f1fc413d..9fd5665289 100644 --- a/lib/js/bs_Array.js +++ b/lib/js/bs_Array.js @@ -13,7 +13,7 @@ function get(arr, i) { function getExn(arr, i) { if (!(i >= 0 && i < arr.length)) { - throw new Error("File \"bs_Array.ml\", line 24, characters 6-12"); + throw new Error("File \"bs_Array.ml\", line 25, characters 6-12"); } return arr[i]; } diff --git a/lib/js/bs_List.js b/lib/js/bs_List.js index 507e28895c..d72435a14f 100644 --- a/lib/js/bs_List.js +++ b/lib/js/bs_List.js @@ -1261,6 +1261,8 @@ function zip(l1, l2) { } } +var size = length; + exports.head = head; exports.tail = tail; exports.add = add; @@ -1276,6 +1278,7 @@ exports.map = map; exports.zipBy = zipBy; exports.mapWithIndex = mapWithIndex; exports.length = length; +exports.size = size; exports.toArray = toArray; exports.reverseConcat = reverseConcat; exports.reverse = reverse; diff --git a/lib/js/bs_Map.js b/lib/js/bs_Map.js index f5326c0654..0beaddee83 100644 --- a/lib/js/bs_Map.js +++ b/lib/js/bs_Map.js @@ -85,7 +85,7 @@ function merge(s1, s2, f) { }; } -function empty(dict) { +function make(dict) { return { cmp: dict[/* cmp */0], data: Bs_MapDict.empty @@ -252,7 +252,7 @@ var Int = 0; var $$String = 0; -exports.empty = empty; +exports.make = make; exports.isEmpty = isEmpty; exports.has = has; exports.cmp = cmp; diff --git a/lib/js/bs_MapIntM.js b/lib/js/bs_MapIntM.js index ea806da2d4..fded5259c1 100644 --- a/lib/js/bs_MapIntM.js +++ b/lib/js/bs_MapIntM.js @@ -3,7 +3,7 @@ var Bs_internalMapInt = require("./bs_internalMapInt.js"); var Bs_internalAVLtree = require("./bs_internalAVLtree.js"); -function empty() { +function make() { return { data: Bs_internalAVLtree.empty }; @@ -13,6 +13,11 @@ function isEmpty(m) { return Bs_internalAVLtree.isEmpty(m.data); } +function clear(m) { + m.data = Bs_internalAVLtree.empty; + return /* () */0; +} + function minKeyUndefined(m) { return Bs_internalAVLtree.minKeyUndefined(m.data); } @@ -290,7 +295,8 @@ function getExn(d, x) { return Bs_internalMapInt.getExn(d.data, x); } -exports.empty = empty; +exports.make = make; +exports.clear = clear; exports.isEmpty = isEmpty; exports.has = has; exports.cmp = cmp; diff --git a/lib/js/bs_MapM.js b/lib/js/bs_MapM.js index c3512b7812..d6491f9268 100644 --- a/lib/js/bs_MapM.js +++ b/lib/js/bs_MapM.js @@ -150,13 +150,18 @@ function update(t, x, f) { } } -function empty(dict) { +function make(dict) { return { cmp: dict[/* cmp */0], data: Bs_internalAVLtree.empty }; } +function clear(m) { + m.data = Bs_internalAVLtree.empty; + return /* () */0; +} + function isEmpty(d) { return Bs_internalAVLtree.isEmpty(d.data); } @@ -318,7 +323,8 @@ var Int = 0; var $$String = 0; -exports.empty = empty; +exports.make = make; +exports.clear = clear; exports.isEmpty = isEmpty; exports.has = has; exports.cmp = cmp; diff --git a/lib/js/bs_MapStringM.js b/lib/js/bs_MapStringM.js index b79f9ff628..759d319f4e 100644 --- a/lib/js/bs_MapStringM.js +++ b/lib/js/bs_MapStringM.js @@ -3,7 +3,7 @@ var Bs_internalAVLtree = require("./bs_internalAVLtree.js"); var Bs_internalMapString = require("./bs_internalMapString.js"); -function empty() { +function make() { return { data: Bs_internalAVLtree.empty }; @@ -13,6 +13,11 @@ function isEmpty(m) { return Bs_internalAVLtree.isEmpty(m.data); } +function clear(m) { + m.data = Bs_internalAVLtree.empty; + return /* () */0; +} + function minKeyUndefined(m) { return Bs_internalAVLtree.minKeyUndefined(m.data); } @@ -290,7 +295,8 @@ function getExn(d, x) { return Bs_internalMapString.getExn(d.data, x); } -exports.empty = empty; +exports.make = make; +exports.clear = clear; exports.isEmpty = isEmpty; exports.has = has; exports.cmp = cmp; diff --git a/lib/js/bs_Set.js b/lib/js/bs_Set.js index 14a6843e13..dbcae2f17b 100644 --- a/lib/js/bs_Set.js +++ b/lib/js/bs_Set.js @@ -102,7 +102,7 @@ function split(m, e) { ]; } -function empty(dict) { +function make(dict) { return { cmp: dict[/* cmp */0], data: Bs_SetDict.empty @@ -235,7 +235,7 @@ var Int = 0; var $$String = 0; -exports.empty = empty; +exports.make = make; exports.ofArray = ofArray; exports.ofSortedArrayUnsafe = ofSortedArrayUnsafe; exports.isEmpty = isEmpty; diff --git a/lib/js/bs_SetIntM.js b/lib/js/bs_SetIntM.js index 6bc26f9c31..685a5f3864 100644 --- a/lib/js/bs_SetIntM.js +++ b/lib/js/bs_SetIntM.js @@ -190,7 +190,7 @@ function mergeMany(d, arr) { return /* () */0; } -function empty() { +function make() { return { data: Bs_internalAVLset.empty }; @@ -446,7 +446,7 @@ function copy(d) { }; } -exports.empty = empty; +exports.make = make; exports.ofArray = ofArray; exports.ofSortedArrayUnsafe = ofSortedArrayUnsafe; exports.copy = copy; diff --git a/lib/js/bs_SetM.js b/lib/js/bs_SetM.js index 6878dd71bb..d868ca9a6b 100644 --- a/lib/js/bs_SetM.js +++ b/lib/js/bs_SetM.js @@ -196,7 +196,7 @@ function mergeMany(d, xs) { return /* () */0; } -function empty(dict) { +function make(dict) { return { cmp: dict[/* cmp */0], data: Bs_internalAVLset.empty @@ -485,7 +485,7 @@ var Int = 0; var $$String = 0; -exports.empty = empty; +exports.make = make; exports.ofArray = ofArray; exports.ofSortedArrayUnsafe = ofSortedArrayUnsafe; exports.copy = copy; diff --git a/lib/js/bs_SetStringM.js b/lib/js/bs_SetStringM.js index 3d44bfcfd3..3f2fc50d41 100644 --- a/lib/js/bs_SetStringM.js +++ b/lib/js/bs_SetStringM.js @@ -190,7 +190,7 @@ function mergeMany(d, arr) { return /* () */0; } -function empty() { +function make() { return { data: Bs_internalAVLset.empty }; @@ -446,7 +446,7 @@ function copy(d) { }; } -exports.empty = empty; +exports.make = make; exports.ofArray = ofArray; exports.ofSortedArrayUnsafe = ofSortedArrayUnsafe; exports.copy = copy; From 9c8aaccd46437a7d49ddbcf7d7b8d26623ce9a51 Mon Sep 17 00:00:00 2001 From: Hongbo Zhang Date: Thu, 1 Feb 2018 11:54:12 +0800 Subject: [PATCH 4/6] add List.flatten/concatMany --- jscomp/others/bs_Array.ml | 2 +- jscomp/others/bs_Array.mli | 2 +- jscomp/others/bs_List.ml | 20 ++- jscomp/others/bs_List.mli | 7 +- jscomp/others/bs_Map.ml | 4 +- jscomp/others/bs_Map.mli | 4 +- jscomp/others/bs_MapDict.ml | 2 +- jscomp/others/bs_MapDict.mli | 4 +- jscomp/others/bs_MapInt.ml | 2 +- jscomp/others/bs_MapInt.mli | 4 +- jscomp/others/bs_MapIntM.mli | 2 +- jscomp/others/bs_MapM.mli | 2 +- jscomp/others/bs_MapString.ml | 2 +- jscomp/others/bs_MapString.mli | 4 +- jscomp/others/bs_MapStringM.mli | 2 +- jscomp/others/bs_Set.ml | 4 +- jscomp/others/bs_Set.mli | 4 +- jscomp/others/bs_SetDict.ml | 2 +- jscomp/others/bs_SetDict.mli | 4 +- jscomp/others/bs_SetInt.ml | 2 +- jscomp/others/bs_SetInt.mli | 4 +- jscomp/others/bs_SetIntM.ml | 2 +- jscomp/others/bs_SetIntM.mli | 4 +- jscomp/others/bs_SetM.ml | 2 +- jscomp/others/bs_SetM.mli | 4 +- jscomp/others/bs_SetString.ml | 2 +- jscomp/others/bs_SetString.mli | 4 +- jscomp/others/bs_SetStringM.ml | 2 +- jscomp/others/bs_SetStringM.mli | 4 +- jscomp/others/map.cppo.ml | 2 +- jscomp/others/map.cppo.mli | 4 +- jscomp/others/mapm.cppo.mli | 2 +- jscomp/others/set.cppo.ml | 2 +- jscomp/others/set.cppo.mli | 4 +- jscomp/others/setm.cppo.ml | 2 +- jscomp/others/setm.cppo.mli | 4 +- jscomp/test/bs_array_test.js | 4 +- jscomp/test/bs_array_test.ml | 4 +- jscomp/test/bs_hashtbl_string_test.ml | 2 +- jscomp/test/bs_list_test.js | 196 ++++++++++++++++++------ jscomp/test/bs_list_test.ml | 25 ++- jscomp/test/bs_map_set_dict_test.ml | 10 +- jscomp/test/bs_mutable_set_test.js | 10 +- jscomp/test/bs_mutable_set_test.ml | 18 +-- jscomp/test/bs_poly_map_test.ml | 2 +- jscomp/test/bs_poly_mutable_set_test.js | 4 +- jscomp/test/bs_poly_mutable_set_test.ml | 6 +- jscomp/test/bs_poly_set_test.js | 6 +- jscomp/test/bs_poly_set_test.ml | 16 +- lib/js/bs_Array.js | 4 +- lib/js/bs_List.js | 25 ++- lib/js/bs_Map.js | 6 +- lib/js/bs_MapDict.js | 4 +- lib/js/bs_MapInt.js | 4 +- lib/js/bs_MapString.js | 4 +- lib/js/bs_Set.js | 6 +- lib/js/bs_SetDict.js | 4 +- lib/js/bs_SetInt.js | 4 +- lib/js/bs_SetIntM.js | 4 +- lib/js/bs_SetM.js | 4 +- lib/js/bs_SetString.js | 4 +- lib/js/bs_SetStringM.js | 4 +- 62 files changed, 326 insertions(+), 181 deletions(-) diff --git a/jscomp/others/bs_Array.ml b/jscomp/others/bs_Array.ml index 1a1e979ec4..89e6cf3602 100644 --- a/jscomp/others/bs_Array.ml +++ b/jscomp/others/bs_Array.ml @@ -225,7 +225,7 @@ let map a f = r -let keepBy a f = +let keep a f = let l = length a in let r = makeUninitializedUnsafe l in let j = ref 0 in diff --git a/jscomp/others/bs_Array.mli b/jscomp/others/bs_Array.mli index eab576b47f..43067f9066 100644 --- a/jscomp/others/bs_Array.mli +++ b/jscomp/others/bs_Array.mli @@ -104,7 +104,7 @@ val map: 'a array -> ('a -> 'b [@bs]) -> 'b array val zipBy: 'a array -> 'b array -> ('a -> 'b -> 'c [@bs]) -> 'c array -val keepBy: 'a array -> ('a -> bool [@bs]) -> 'a array +val keep: 'a array -> ('a -> bool [@bs]) -> 'a array val keepMap: 'a array -> ('a -> 'b option [@bs]) -> 'b array diff --git a/jscomp/others/bs_List.ml b/jscomp/others/bs_List.ml index 35f596dd82..47c57fca7f 100644 --- a/jscomp/others/bs_List.ml +++ b/jscomp/others/bs_List.ml @@ -433,15 +433,27 @@ let rec flattenAux prec xs = | h::r -> flattenAux (copyAuxCont h prec) r -let rec concatMany xs = +let rec flatten xs = match xs with | [] -> [] - | []::xs -> concatMany xs + | []::xs -> flatten xs | (h::t):: r -> let cell = mutableCell h [] in flattenAux (copyAuxCont t cell) r ; cell +let concatMany xs = + match xs with + | [||] -> [] + | [|x|] -> x + | _ -> + let len = A.length xs in + let v = ref (A.getUnsafe xs (len - 1)) in + for i = len - 2 downto 0 do + v := concat (A.getUnsafe xs i) !v + done ; + !v + let rec mapRevAux f accu xs = match xs with | [] -> accu @@ -603,7 +615,7 @@ let rec getBy xs p = else getBy l p -let rec keepBy xs p = +let rec keep xs p = match xs with | [] -> [] | h::t -> @@ -614,7 +626,7 @@ let rec keepBy xs p = cell end else - keepBy t p + keep t p let rec keepMap xs p = diff --git a/jscomp/others/bs_List.mli b/jscomp/others/bs_List.mli index 633c409095..8e35a066f8 100644 --- a/jscomp/others/bs_List.mli +++ b/jscomp/others/bs_List.mli @@ -71,8 +71,9 @@ val reverseConcat: 'a t -> 'a t -> 'a t val reverse: 'a t -> 'a t -val concatMany: 'a t t -> 'a t - +val flatten: 'a t t -> 'a t +val concatMany: 'a t array -> 'a t + val mapReverse: 'a t -> ('a -> 'b [@bs]) -> 'b t (** [mapReverse a f] is semantically equivalent to [reverse (map a f)] *) @@ -127,7 +128,7 @@ val removeAssocByReference: ('a * 'b) t -> 'a -> ('a * 'b) t val getBy: 'a t -> ('a -> bool [@bs]) -> 'a option -val keepBy: 'a t -> ('a -> bool [@bs]) -> 'a t +val keep: 'a t -> ('a -> bool [@bs]) -> 'a t val keepMap: 'a t -> ('a -> 'b option [@bs]) -> 'b t val partition: 'a t -> ('a -> bool [@bs]) -> 'a t * 'a t diff --git a/jscomp/others/bs_Map.ml b/jscomp/others/bs_Map.ml index 8cff8a2bc1..70f08b6160 100644 --- a/jscomp/others/bs_Map.ml +++ b/jscomp/others/bs_Map.ml @@ -81,8 +81,8 @@ let every m f = N.every (S.data m) f let some m f = N.some (S.data m) f -let keepBy m f = - S.t ~cmp:(S.cmp m) ~data:(N.keepBy (S.data m) f) +let keep m f = + S.t ~cmp:(S.cmp m) ~data:(N.keep (S.data m) f) let partition m p = let cmp = S.cmp m in diff --git a/jscomp/others/bs_Map.mli b/jscomp/others/bs_Map.mli index abdb191ec7..2b873a80b9 100644 --- a/jscomp/others/bs_Map.mli +++ b/jscomp/others/bs_Map.mli @@ -131,11 +131,11 @@ val mergeMany: ('a * 'b) array -> ('a, 'b, 'id) t -val keepBy: +val keep: ('k, 'a, 'id) t -> ('k -> 'a -> bool [@bs]) -> ('k, 'a, 'id) t -(** [keepBy m p] returns the map with all the bindings in [m] +(** [keep m p] returns the map with all the bindings in [m] that satisfy predicate [p]. *) val partition: diff --git a/jscomp/others/bs_MapDict.ml b/jscomp/others/bs_MapDict.ml index 3975f73cd5..ee8bb440e3 100644 --- a/jscomp/others/bs_MapDict.ml +++ b/jscomp/others/bs_MapDict.ml @@ -61,7 +61,7 @@ let getExn = N.getExn let mapWithKey = N.mapWithKey let map = N.map -let keepBy = N.filterShared +let keep = N.filterShared let partition = N.partitionShared let checkInvariantInternal = N.checkInvariantInternal let rec set (t : _ t) newK newD ~cmp = diff --git a/jscomp/others/bs_MapDict.mli b/jscomp/others/bs_MapDict.mli index 213cd792b3..58de008eec 100644 --- a/jscomp/others/bs_MapDict.mli +++ b/jscomp/others/bs_MapDict.mli @@ -144,11 +144,11 @@ val mergeMany: cmp:('a, 'id) cmp -> ('a, 'b, 'id) t -val keepBy: +val keep: ('k, 'a, 'id) t -> ('k -> 'a -> bool [@bs]) -> ('k, 'a, 'id) t -(** [keepBy m p] returns the map with all the bindings in [m] +(** [keep m p] returns the map with all the bindings in [m] that satisfy predicate [p]. *) val partition: diff --git a/jscomp/others/bs_MapInt.ml b/jscomp/others/bs_MapInt.ml index a8461994fe..37eaeeb345 100644 --- a/jscomp/others/bs_MapInt.ml +++ b/jscomp/others/bs_MapInt.ml @@ -26,7 +26,7 @@ let mapWithKey = N.mapWithKey let reduce = N.reduce let every = N.every let some = N.some -let keepBy = N.filterShared +let keep = N.filterShared let partition = N.partitionShared let size = N.size let toList = N.toList diff --git a/jscomp/others/bs_MapInt.mli b/jscomp/others/bs_MapInt.mli index ce0ed360fe..f277b54cb9 100644 --- a/jscomp/others/bs_MapInt.mli +++ b/jscomp/others/bs_MapInt.mli @@ -78,11 +78,11 @@ val merge: value, is determined with the function [f]. *) -val keepBy: +val keep: 'a t -> (key -> 'a -> bool [@bs]) -> 'a t -(** [keepBy m p] returns the map with all the bindings in [m] +(** [keep m p] returns the map with all the bindings in [m] that satisfy predicate [p]. *) diff --git a/jscomp/others/bs_MapIntM.mli b/jscomp/others/bs_MapIntM.mli index 9f5e822632..fa6a684fa5 100644 --- a/jscomp/others/bs_MapIntM.mli +++ b/jscomp/others/bs_MapIntM.mli @@ -91,7 +91,7 @@ val checkInvariantInternal: _ t -> bool (****************************************************************************) -(*TODO: add functional [merge, partition, keepBy, split]*) +(*TODO: add functional [merge, partition, keep, split]*) val remove: 'a t -> key -> unit (** [remove m x] do the in-place modification *) diff --git a/jscomp/others/bs_MapM.mli b/jscomp/others/bs_MapM.mli index 56f6f3918c..ab3ee4770c 100644 --- a/jscomp/others/bs_MapM.mli +++ b/jscomp/others/bs_MapM.mli @@ -91,7 +91,7 @@ val getExn: ('k, 'a, 'id) t -> 'k -> 'a val checkInvariantInternal: _ t -> bool (****************************************************************************) -(*TODO: add functional [merge, partition, keepBy, split]*) +(*TODO: add functional [merge, partition, keep, split]*) val remove: ('k, 'a, 'id) t -> 'k -> unit (** [remove m x] do the in-place modification, diff --git a/jscomp/others/bs_MapString.ml b/jscomp/others/bs_MapString.ml index 546cc2f334..1ad993f06b 100644 --- a/jscomp/others/bs_MapString.ml +++ b/jscomp/others/bs_MapString.ml @@ -26,7 +26,7 @@ let mapWithKey = N.mapWithKey let reduce = N.reduce let every = N.every let some = N.some -let keepBy = N.filterShared +let keep = N.filterShared let partition = N.partitionShared let size = N.size let toList = N.toList diff --git a/jscomp/others/bs_MapString.mli b/jscomp/others/bs_MapString.mli index e2a30c95da..44ac1a41d5 100644 --- a/jscomp/others/bs_MapString.mli +++ b/jscomp/others/bs_MapString.mli @@ -78,11 +78,11 @@ val merge: value, is determined with the function [f]. *) -val keepBy: +val keep: 'a t -> (key -> 'a -> bool [@bs]) -> 'a t -(** [keepBy m p] returns the map with all the bindings in [m] +(** [keep m p] returns the map with all the bindings in [m] that satisfy predicate [p]. *) diff --git a/jscomp/others/bs_MapStringM.mli b/jscomp/others/bs_MapStringM.mli index a7daeaeca1..505d052bd7 100644 --- a/jscomp/others/bs_MapStringM.mli +++ b/jscomp/others/bs_MapStringM.mli @@ -91,7 +91,7 @@ val checkInvariantInternal: _ t -> bool (****************************************************************************) -(*TODO: add functional [merge, partition, keepBy, split]*) +(*TODO: add functional [merge, partition, keep, split]*) val remove: 'a t -> key -> unit (** [remove m x] do the in-place modification *) diff --git a/jscomp/others/bs_Set.ml b/jscomp/others/bs_Set.ml index a817719577..731f9b1e2a 100644 --- a/jscomp/others/bs_Set.ml +++ b/jscomp/others/bs_Set.ml @@ -106,8 +106,8 @@ let every m f = N.every (S.data m) f let some m f = N.some (S.data m) f -let keepBy m f = - S.t ~cmp:(S.cmp m) ~data:(N.keepBy (S.data m) f ) +let keep m f = + S.t ~cmp:(S.cmp m) ~data:(N.keep (S.data m) f ) let partition m f = let l,r = N.partition (S.data m) f in diff --git a/jscomp/others/bs_Set.mli b/jscomp/others/bs_Set.mli index 20bd092a52..6914a87492 100644 --- a/jscomp/others/bs_Set.mli +++ b/jscomp/others/bs_Set.mli @@ -73,8 +73,8 @@ val every: ('elt, 'id) t -> ('elt -> bool [@bs]) -> bool val some: ('elt, 'id) t -> ('elt -> bool [@bs]) -> bool (** [some p s] checks if at least one element of the set satisfies the predicate [p]. *) -val keepBy: ('elt, 'id) t -> ('elt -> bool [@bs]) -> ('elt, 'id) t -(** [keepBy m p] returns the set of all elements in [s] +val keep: ('elt, 'id) t -> ('elt -> bool [@bs]) -> ('elt, 'id) t +(** [keep m p] returns the set of all elements in [s] that satisfy predicate [p]. *) val partition: ('elt, 'id) t -> ('elt -> bool [@bs]) -> ('elt, 'id) t * ('elt, 'id) t (** [partition m p] returns a pair of sets [(s1, s2)], where diff --git a/jscomp/others/bs_SetDict.ml b/jscomp/others/bs_SetDict.ml index 2ec882a6a3..884d468e02 100644 --- a/jscomp/others/bs_SetDict.ml +++ b/jscomp/others/bs_SetDict.ml @@ -225,7 +225,7 @@ let getUndefined = N.getUndefined let ofSortedArrayUnsafe = N.ofSortedArrayUnsafe let subset = N.subset -let keepBy = N.filterShared +let keep = N.filterShared let partition = N.partitionShared let checkInvariantInternal = N.checkInvariantInternal diff --git a/jscomp/others/bs_SetDict.mli b/jscomp/others/bs_SetDict.mli index 84177c114c..dfaf371eb2 100644 --- a/jscomp/others/bs_SetDict.mli +++ b/jscomp/others/bs_SetDict.mli @@ -103,8 +103,8 @@ val every: ('elt, 'id) t -> ('elt -> bool [@bs]) -> bool val some: ('elt, 'id) t -> ('elt -> bool [@bs]) -> bool (** [some p s] checks if at least one element of the set satisfies the predicate [p]. *) -val keepBy: ('elt, 'id) t -> ('elt -> bool [@bs]) -> ('elt, 'id) t -(** [keepBy m p] returns the set of all elements in [s] +val keep: ('elt, 'id) t -> ('elt -> bool [@bs]) -> ('elt, 'id) t +(** [keep m p] returns the set of all elements in [s] that satisfy predicate [p]. *) val partition: ('elt, 'id) t -> ('elt -> bool [@bs]) -> ('elt, 'id) t * ('elt, 'id) t (** [partition m p] returns a pair of sets [(s1, s2)], where diff --git a/jscomp/others/bs_SetInt.ml b/jscomp/others/bs_SetInt.ml index cec7fef6f7..fadd143ffd 100644 --- a/jscomp/others/bs_SetInt.ml +++ b/jscomp/others/bs_SetInt.ml @@ -18,7 +18,7 @@ let forEach = N.forEach let reduce = N.reduce let every = N.every let some = N.some -let keepBy = N.filterShared +let keep = N.filterShared let partition = N.partitionShared let size = N.size let toList = N.toList diff --git a/jscomp/others/bs_SetInt.mli b/jscomp/others/bs_SetInt.mli index 02a302c114..e733efe6ab 100644 --- a/jscomp/others/bs_SetInt.mli +++ b/jscomp/others/bs_SetInt.mli @@ -77,8 +77,8 @@ val some: t -> (elt -> bool [@bs]) -> bool (** [some p s] checks if at least one element of the set satisfies the predicate [p]. Oder unspecified. *) -val keepBy: t -> (elt -> bool [@bs]) -> t -(** [keepBy p s] returns the set of all elements in [s] +val keep: t -> (elt -> bool [@bs]) -> t +(** [keep p s] returns the set of all elements in [s] that satisfy predicate [p]. *) val partition: t -> (elt -> bool [@bs]) -> t * t diff --git a/jscomp/others/bs_SetIntM.ml b/jscomp/others/bs_SetIntM.ml index 12bd872dcd..fc39c12b64 100644 --- a/jscomp/others/bs_SetIntM.ml +++ b/jscomp/others/bs_SetIntM.ml @@ -229,7 +229,7 @@ let split d key = ~data:(N.ofSortedArrayAux arr (i+1) (len - i - 1)) ), true -let keepBy d p = +let keep d p = t ~data:(N.filterCopy (data d) p ) let partition d p = let a , b = N.partitionCopy (data d) p in diff --git a/jscomp/others/bs_SetIntM.mli b/jscomp/others/bs_SetIntM.mli index 8bd24ae7f8..52a6105e33 100644 --- a/jscomp/others/bs_SetIntM.mli +++ b/jscomp/others/bs_SetIntM.mli @@ -67,8 +67,8 @@ val some: t -> (elt -> bool [@bs]) -> bool (** [some p s] checks if at least one element of the set satisfies the predicate [p]. Oder unspecified. *) -val keepBy: t -> (elt -> bool [@bs]) -> t -(** [keepBy s p] returns a fresh copy of the set of all elements in [s] +val keep: t -> (elt -> bool [@bs]) -> t +(** [keep s p] returns a fresh copy of the set of all elements in [s] that satisfy predicate [p]. *) val partition: t -> (elt -> bool [@bs]) -> t * t diff --git a/jscomp/others/bs_SetM.ml b/jscomp/others/bs_SetM.ml index 3f3dcb2cff..a948be96e9 100644 --- a/jscomp/others/bs_SetM.ml +++ b/jscomp/others/bs_SetM.ml @@ -271,7 +271,7 @@ let split d key = ~cmp ), true -let keepBy d p = +let keep d p = S.t ~data:(N.filterCopy (S.data d) p ) ~cmp:(S.cmp d) let partition d p = diff --git a/jscomp/others/bs_SetM.mli b/jscomp/others/bs_SetM.mli index 2608343b14..8fdae8b339 100644 --- a/jscomp/others/bs_SetM.mli +++ b/jscomp/others/bs_SetM.mli @@ -73,8 +73,8 @@ val some: ('elt, 'id) t -> ('elt -> bool [@bs]) -> bool (** [some p s] checks if at least one element of the set satisfies the predicate [p]. *) -val keepBy: ('elt, 'id) t -> ('elt -> bool [@bs]) -> ('elt, 'id) t -(** [keepBy p s] returns the set of all elements in [s] +val keep: ('elt, 'id) t -> ('elt -> bool [@bs]) -> ('elt, 'id) t +(** [keep p s] returns the set of all elements in [s] that satisfy predicate [p]. *) val partition: ('elt, 'id) t -> ('elt -> bool [@bs]) -> ('elt, 'id) t * ('elt, 'id) t (** [partition p s] returns a pair of sets [(s1, s2)], where diff --git a/jscomp/others/bs_SetString.ml b/jscomp/others/bs_SetString.ml index 15e81ba318..55486040f0 100644 --- a/jscomp/others/bs_SetString.ml +++ b/jscomp/others/bs_SetString.ml @@ -18,7 +18,7 @@ let forEach = N.forEach let reduce = N.reduce let every = N.every let some = N.some -let keepBy = N.filterShared +let keep = N.filterShared let partition = N.partitionShared let size = N.size let toList = N.toList diff --git a/jscomp/others/bs_SetString.mli b/jscomp/others/bs_SetString.mli index 59c7a475ea..19aabf27b8 100644 --- a/jscomp/others/bs_SetString.mli +++ b/jscomp/others/bs_SetString.mli @@ -77,8 +77,8 @@ val some: t -> (elt -> bool [@bs]) -> bool (** [some p s] checks if at least one element of the set satisfies the predicate [p]. Oder unspecified. *) -val keepBy: t -> (elt -> bool [@bs]) -> t -(** [keepBy p s] returns the set of all elements in [s] +val keep: t -> (elt -> bool [@bs]) -> t +(** [keep p s] returns the set of all elements in [s] that satisfy predicate [p]. *) val partition: t -> (elt -> bool [@bs]) -> t * t diff --git a/jscomp/others/bs_SetStringM.ml b/jscomp/others/bs_SetStringM.ml index b3cbbf10fa..4354ed99af 100644 --- a/jscomp/others/bs_SetStringM.ml +++ b/jscomp/others/bs_SetStringM.ml @@ -229,7 +229,7 @@ let split d key = ~data:(N.ofSortedArrayAux arr (i+1) (len - i - 1)) ), true -let keepBy d p = +let keep d p = t ~data:(N.filterCopy (data d) p ) let partition d p = let a , b = N.partitionCopy (data d) p in diff --git a/jscomp/others/bs_SetStringM.mli b/jscomp/others/bs_SetStringM.mli index 58a5fa19cd..c35aa892ca 100644 --- a/jscomp/others/bs_SetStringM.mli +++ b/jscomp/others/bs_SetStringM.mli @@ -67,8 +67,8 @@ val some: t -> (elt -> bool [@bs]) -> bool (** [some p s] checks if at least one element of the set satisfies the predicate [p]. Oder unspecified. *) -val keepBy: t -> (elt -> bool [@bs]) -> t -(** [keepBy s p] returns a fresh copy of the set of all elements in [s] +val keep: t -> (elt -> bool [@bs]) -> t +(** [keep s p] returns a fresh copy of the set of all elements in [s] that satisfy predicate [p]. *) val partition: t -> (elt -> bool [@bs]) -> t * t diff --git a/jscomp/others/map.cppo.ml b/jscomp/others/map.cppo.ml index f9121dc950..d43a579947 100644 --- a/jscomp/others/map.cppo.ml +++ b/jscomp/others/map.cppo.ml @@ -31,7 +31,7 @@ let mapWithKey = N.mapWithKey let reduce = N.reduce let every = N.every let some = N.some -let keepBy = N.filterShared +let keep = N.filterShared let partition = N.partitionShared let size = N.size let toList = N.toList diff --git a/jscomp/others/map.cppo.mli b/jscomp/others/map.cppo.mli index e2e28085ae..f02fa42a96 100644 --- a/jscomp/others/map.cppo.mli +++ b/jscomp/others/map.cppo.mli @@ -82,11 +82,11 @@ val merge: value, is determined with the function [f]. *) -val keepBy: +val keep: 'a t -> (key -> 'a -> bool [@bs]) -> 'a t -(** [keepBy m p] returns the map with all the bindings in [m] +(** [keep m p] returns the map with all the bindings in [m] that satisfy predicate [p]. *) diff --git a/jscomp/others/mapm.cppo.mli b/jscomp/others/mapm.cppo.mli index 8769ab51e4..77d84b95d5 100644 --- a/jscomp/others/mapm.cppo.mli +++ b/jscomp/others/mapm.cppo.mli @@ -94,7 +94,7 @@ val checkInvariantInternal: _ t -> bool (****************************************************************************) -(*TODO: add functional [merge, partition, keepBy, split]*) +(*TODO: add functional [merge, partition, keep, split]*) val remove: 'a t -> key -> unit (** [remove m x] do the in-place modification *) diff --git a/jscomp/others/set.cppo.ml b/jscomp/others/set.cppo.ml index 40c63b5178..034c95bb1a 100644 --- a/jscomp/others/set.cppo.ml +++ b/jscomp/others/set.cppo.ml @@ -22,7 +22,7 @@ let forEach = N.forEach let reduce = N.reduce let every = N.every let some = N.some -let keepBy = N.filterShared +let keep = N.filterShared let partition = N.partitionShared let size = N.size let toList = N.toList diff --git a/jscomp/others/set.cppo.mli b/jscomp/others/set.cppo.mli index 5321d8c9e8..06016e1955 100644 --- a/jscomp/others/set.cppo.mli +++ b/jscomp/others/set.cppo.mli @@ -80,8 +80,8 @@ val some: t -> (elt -> bool [@bs]) -> bool (** [some p s] checks if at least one element of the set satisfies the predicate [p]. Oder unspecified. *) -val keepBy: t -> (elt -> bool [@bs]) -> t -(** [keepBy p s] returns the set of all elements in [s] +val keep: t -> (elt -> bool [@bs]) -> t +(** [keep p s] returns the set of all elements in [s] that satisfy predicate [p]. *) val partition: t -> (elt -> bool [@bs]) -> t * t diff --git a/jscomp/others/setm.cppo.ml b/jscomp/others/setm.cppo.ml index 26121476f5..fcabf54519 100644 --- a/jscomp/others/setm.cppo.ml +++ b/jscomp/others/setm.cppo.ml @@ -234,7 +234,7 @@ let split d key = ~data:(N.ofSortedArrayAux arr (i+1) (len - i - 1)) ), true -let keepBy d p = +let keep d p = t ~data:(N.filterCopy (data d) p ) let partition d p = let a , b = N.partitionCopy (data d) p in diff --git a/jscomp/others/setm.cppo.mli b/jscomp/others/setm.cppo.mli index 1471f59c90..93878180fb 100644 --- a/jscomp/others/setm.cppo.mli +++ b/jscomp/others/setm.cppo.mli @@ -70,8 +70,8 @@ val some: t -> (elt -> bool [@bs]) -> bool (** [some p s] checks if at least one element of the set satisfies the predicate [p]. Oder unspecified. *) -val keepBy: t -> (elt -> bool [@bs]) -> t -(** [keepBy s p] returns a fresh copy of the set of all elements in [s] +val keep: t -> (elt -> bool [@bs]) -> t +(** [keep s p] returns a fresh copy of the set of all elements in [s] that satisfy predicate [p]. *) val partition: t -> (elt -> bool [@bs]) -> t * t diff --git a/jscomp/test/bs_array_test.js b/jscomp/test/bs_array_test.js index b228ac626e..c16221a17b 100644 --- a/jscomp/test/bs_array_test.js +++ b/jscomp/test/bs_array_test.js @@ -329,11 +329,11 @@ var v$1 = Bs_Array.makeBy(10, (function (i) { return i; })); -var v0 = Bs_Array.keepBy(v$1, (function (x) { +var v0 = Bs_Array.keep(v$1, (function (x) { return +(x % 2 === 0); })); -var v1 = Bs_Array.keepBy(v$1, (function (x) { +var v1 = Bs_Array.keep(v$1, (function (x) { return +(x % 3 === 0); })); diff --git a/jscomp/test/bs_array_test.ml b/jscomp/test/bs_array_test.ml index ebdcf426ae..35243e292a 100644 --- a/jscomp/test/bs_array_test.ml +++ b/jscomp/test/bs_array_test.ml @@ -101,8 +101,8 @@ let () = let () = let v = A.makeBy 10 (fun[@bs] i -> i ) in - let v0 = A.keepBy v (fun[@bs] x -> x mod 2 = 0) in - let v1 = A.keepBy v (fun[@bs] x -> x mod 3 = 0) in + let v0 = A.keep v (fun[@bs] x -> x mod 2 = 0) in + let v1 = A.keep v (fun[@bs] x -> x mod 3 = 0) in let v2 = A.keepMap v (fun[@bs] x -> if x mod 2 = 0 then Some (x + 1) else None ) in eq __LOC__ v0 [|0;2;4;6;8|]; eq __LOC__ v1 [|0;3;6;9|]; diff --git a/jscomp/test/bs_hashtbl_string_test.ml b/jscomp/test/bs_hashtbl_string_test.ml index 5842de2597..4276f058d8 100644 --- a/jscomp/test/bs_hashtbl_string_test.ml +++ b/jscomp/test/bs_hashtbl_string_test.ml @@ -86,7 +86,7 @@ module Md = Bs.Map module Md0 = Bs.MapDict let bench3 (type t) (m : (string,t) Bs.Dict.comparable) = - let empty = Md.empty m in + let empty = Md.make m in let module String = (val m) in let cmp = String.cmp in let table = ref (Md.getData empty) in diff --git a/jscomp/test/bs_list_test.js b/jscomp/test/bs_list_test.js index 4c57cc9e68..a47ce80099 100644 --- a/jscomp/test/bs_list_test.js +++ b/jscomp/test/bs_list_test.js @@ -90,7 +90,7 @@ eq("File \"bs_list_test.ml\", line 36, characters 5-12", Bs_List.map(u, (functio ] ]); -eq("FLATTEN", Bs_List.concatMany(/* :: */[ +eq("FLATTEN", Bs_List.flatten(/* :: */[ /* :: */[ 1, /* [] */0 @@ -139,9 +139,9 @@ eq("FLATTEN", Bs_List.concatMany(/* :: */[ ] ]); -eq("FLATTEN", Bs_List.concatMany(/* [] */0), /* [] */0); +eq("FLATTEN", Bs_List.flatten(/* [] */0), /* [] */0); -eq("FLATTEN", Bs_List.concatMany(/* :: */[ +eq("FLATTEN", Bs_List.flatten(/* :: */[ /* [] */0, /* :: */[ /* [] */0, @@ -179,7 +179,109 @@ eq("FLATTEN", Bs_List.concatMany(/* :: */[ ] ]); -eq("File \"bs_list_test.ml\", line 50, characters 5-12", Bs_List.toArray(Bs_List.concat(Bs_List.makeBy(100, (function (i) { +eq("CONCATMANY", Bs_List.concatMany(/* array */[ + /* :: */[ + 1, + /* [] */0 + ], + /* :: */[ + 2, + /* [] */0 + ], + /* :: */[ + 3, + /* [] */0 + ], + /* [] */0, + Bs_List.makeBy(4, (function (i) { + return i; + })) + ]), /* :: */[ + 1, + /* :: */[ + 2, + /* :: */[ + 3, + /* :: */[ + 0, + /* :: */[ + 1, + /* :: */[ + 2, + /* :: */[ + 3, + /* [] */0 + ] + ] + ] + ] + ] + ] + ]); + +eq("CONCATMANY", Bs_List.concatMany(/* array */[]), /* [] */0); + +eq("CONCATMANY", Bs_List.concatMany(/* array */[ + /* [] */0, + /* [] */0, + /* :: */[ + 2, + /* [] */0 + ], + /* :: */[ + 1, + /* [] */0 + ], + /* :: */[ + 2, + /* [] */0 + ], + /* [] */0 + ]), /* :: */[ + 2, + /* :: */[ + 1, + /* :: */[ + 2, + /* [] */0 + ] + ] + ]); + +eq("CONCATMANY", Bs_List.concatMany(/* array */[ + /* [] */0, + /* [] */0, + /* :: */[ + 2, + /* :: */[ + 3, + /* [] */0 + ] + ], + /* :: */[ + 1, + /* [] */0 + ], + /* :: */[ + 2, + /* [] */0 + ], + /* [] */0 + ]), /* :: */[ + 2, + /* :: */[ + 3, + /* :: */[ + 1, + /* :: */[ + 2, + /* [] */0 + ] + ] + ] + ]); + +eq("File \"bs_list_test.ml\", line 61, characters 5-12", Bs_List.toArray(Bs_List.concat(Bs_List.makeBy(100, (function (i) { return i; })), Bs_List.makeBy(100, (function (i) { return i; @@ -451,7 +553,7 @@ eq("UNZIP", Bs_List.unzip(/* :: */[ ] ]); -eq("FILTER", Bs_List.keepBy(/* :: */[ +eq("FILTER", Bs_List.keep(/* :: */[ 1, /* :: */[ 2, @@ -471,7 +573,7 @@ eq("FILTER", Bs_List.keepBy(/* :: */[ ] ]); -eq("FILTER", Bs_List.keepBy(/* :: */[ +eq("FILTER", Bs_List.keep(/* :: */[ 1, /* :: */[ 3, @@ -482,9 +584,9 @@ eq("FILTER", Bs_List.keepBy(/* :: */[ ] ], mod2), /* [] */0); -eq("FILTER", Bs_List.keepBy(/* [] */0, mod2), /* [] */0); +eq("FILTER", Bs_List.keep(/* [] */0, mod2), /* [] */0); -eq("FILTER", Bs_List.keepBy(/* :: */[ +eq("FILTER", Bs_List.keep(/* :: */[ 2, /* :: */[ 2, @@ -597,7 +699,7 @@ eq("MAP2", Bs_List.reverse(Bs_List.mapReverse2(length_10_id, length_10_id, add)) var xs = Bs_List.reverse(Bs_List.mapReverse2(length_8_id, length_10_id, add)); -eq("File \"bs_list_test.ml\", line 127, characters 5-12", Bs_List.length(xs), 8); +eq("File \"bs_list_test.ml\", line 138, characters 5-12", Bs_List.length(xs), 8); eq("MAP2", xs, Bs_List.zipBy(length_10_id, length_8_id, add)); @@ -1036,7 +1138,7 @@ eq("REMOVEASSOQ", Bs_List.removeAssoc(/* :: */[ ] ]); -eq("File \"bs_list_test.ml\", line 176, characters 5-12", /* tuple */[ +eq("File \"bs_list_test.ml\", line 187, characters 5-12", /* tuple */[ Bs_List.head(length_10_id), Bs_List.tail(length_10_id) ], /* tuple */[ @@ -1044,59 +1146,59 @@ eq("File \"bs_list_test.ml\", line 176, characters 5-12", /* tuple */[ Bs_List.drop(length_10_id, 1) ]); -eq("File \"bs_list_test.ml\", line 177, characters 5-12", Bs_List.head(/* [] */0), /* None */0); +eq("File \"bs_list_test.ml\", line 188, characters 5-12", Bs_List.head(/* [] */0), /* None */0); Bs_List.forEachWithIndex(length_10_id, (function (i, x) { - return eq("File \"bs_list_test.ml\", line 179, characters 9-16", Bs_List.get(length_10_id, i), /* Some */[x]); + return eq("File \"bs_list_test.ml\", line 190, characters 9-16", Bs_List.get(length_10_id, i), /* Some */[x]); })); -eq("File \"bs_list_test.ml\", line 180, characters 5-12", Bs_List.tail(/* [] */0), /* None */0); +eq("File \"bs_list_test.ml\", line 191, characters 5-12", Bs_List.tail(/* [] */0), /* None */0); -eq("File \"bs_list_test.ml\", line 181, characters 5-12", Bs_List.drop(/* [] */0, 3), /* None */0); +eq("File \"bs_list_test.ml\", line 192, characters 5-12", Bs_List.drop(/* [] */0, 3), /* None */0); -eq("File \"bs_list_test.ml\", line 182, characters 5-12", Bs_List.mapWithIndex(/* [] */0, (function (i, x) { +eq("File \"bs_list_test.ml\", line 193, characters 5-12", Bs_List.mapWithIndex(/* [] */0, (function (i, x) { return i + x | 0; })), /* [] */0); -eq("File \"bs_list_test.ml\", line 183, characters 5-12", Bs_List.get(length_10_id, -1), /* None */0); +eq("File \"bs_list_test.ml\", line 194, characters 5-12", Bs_List.get(length_10_id, -1), /* None */0); -eq("File \"bs_list_test.ml\", line 184, characters 5-12", Bs_List.get(length_10_id, 12), /* None */0); +eq("File \"bs_list_test.ml\", line 195, characters 5-12", Bs_List.get(length_10_id, 12), /* None */0); -eq("File \"bs_list_test.ml\", line 185, characters 5-12", sum(/* [] */0), 0); +eq("File \"bs_list_test.ml\", line 196, characters 5-12", sum(/* [] */0), 0); -eq("File \"bs_list_test.ml\", line 186, characters 5-12", sum(length_10_id), 45); +eq("File \"bs_list_test.ml\", line 197, characters 5-12", sum(length_10_id), 45); -eq("File \"bs_list_test.ml\", line 187, characters 5-12", Bs_List.makeBy(0, id), /* [] */0); +eq("File \"bs_list_test.ml\", line 198, characters 5-12", Bs_List.makeBy(0, id), /* [] */0); -eq("File \"bs_list_test.ml\", line 188, characters 5-12", Bs_List.reverse(Bs_List.reverse(length_10_id)), length_10_id); +eq("File \"bs_list_test.ml\", line 199, characters 5-12", Bs_List.reverse(Bs_List.reverse(length_10_id)), length_10_id); -eq("File \"bs_list_test.ml\", line 189, characters 5-12", Bs_List.reverse(Bs_List.reverse(length_8_id)), length_8_id); +eq("File \"bs_list_test.ml\", line 200, characters 5-12", Bs_List.reverse(Bs_List.reverse(length_8_id)), length_8_id); -eq("File \"bs_list_test.ml\", line 190, characters 5-12", Bs_List.reverse(/* [] */0), /* [] */0); +eq("File \"bs_list_test.ml\", line 201, characters 5-12", Bs_List.reverse(/* [] */0), /* [] */0); -eq("File \"bs_list_test.ml\", line 191, characters 5-12", Bs_List.reverse(Bs_List.mapReverse(length_10_id, succx)), Bs_List.map(length_10_id, succx)); +eq("File \"bs_list_test.ml\", line 202, characters 5-12", Bs_List.reverse(Bs_List.mapReverse(length_10_id, succx)), Bs_List.map(length_10_id, succx)); -eq("File \"bs_list_test.ml\", line 194, characters 5-12", Bs_List.reduce(length_10_id, 0, add), 45); +eq("File \"bs_list_test.ml\", line 205, characters 5-12", Bs_List.reduce(length_10_id, 0, add), 45); -eq("File \"bs_list_test.ml\", line 196, characters 5-12", Bs_List.reduceReverse(length_10_id, 0, add), 45); +eq("File \"bs_list_test.ml\", line 207, characters 5-12", Bs_List.reduceReverse(length_10_id, 0, add), 45); -eq("File \"bs_list_test.ml\", line 200, characters 5-12", sum2(length_10_id, length_10_id), 90); +eq("File \"bs_list_test.ml\", line 211, characters 5-12", sum2(length_10_id, length_10_id), 90); -eq("File \"bs_list_test.ml\", line 201, characters 5-12", sum2(length_8_id, length_10_id), 56); +eq("File \"bs_list_test.ml\", line 212, characters 5-12", sum2(length_8_id, length_10_id), 56); -eq("File \"bs_list_test.ml\", line 202, characters 5-12", Bs_List.reduce2(length_10_id, length_8_id, 0, (function (acc, x, y) { +eq("File \"bs_list_test.ml\", line 213, characters 5-12", Bs_List.reduce2(length_10_id, length_8_id, 0, (function (acc, x, y) { return (acc + x | 0) + y | 0; })), 56); -eq("File \"bs_list_test.ml\", line 204, characters 5-12", Bs_List.reduceReverse2(length_10_id, length_8_id, 0, (function (acc, x, y) { +eq("File \"bs_list_test.ml\", line 215, characters 5-12", Bs_List.reduceReverse2(length_10_id, length_8_id, 0, (function (acc, x, y) { return (acc + x | 0) + y | 0; })), 56); -eq("File \"bs_list_test.ml\", line 206, characters 5-12", Bs_List.reduceReverse2(length_10_id, length_10_id, 0, (function (acc, x, y) { +eq("File \"bs_list_test.ml\", line 217, characters 5-12", Bs_List.reduceReverse2(length_10_id, length_10_id, 0, (function (acc, x, y) { return (acc + x | 0) + y | 0; })), 90); -eq("File \"bs_list_test.ml\", line 208, characters 5-12", Bs_List.every(/* :: */[ +eq("File \"bs_list_test.ml\", line 219, characters 5-12", Bs_List.every(/* :: */[ 2, /* :: */[ 4, @@ -1107,14 +1209,14 @@ eq("File \"bs_list_test.ml\", line 208, characters 5-12", Bs_List.every(/* :: */ ] ], mod2), /* true */1); -eq("File \"bs_list_test.ml\", line 209, characters 5-12", Bs_List.every(/* :: */[ +eq("File \"bs_list_test.ml\", line 220, characters 5-12", Bs_List.every(/* :: */[ 1, /* [] */0 ], mod2), /* false */0); -eq("File \"bs_list_test.ml\", line 210, characters 5-12", Bs_List.every(/* [] */0, mod2), /* true */1); +eq("File \"bs_list_test.ml\", line 221, characters 5-12", Bs_List.every(/* [] */0, mod2), /* true */1); -eq("File \"bs_list_test.ml\", line 211, characters 5-12", Bs_List.some(/* :: */[ +eq("File \"bs_list_test.ml\", line 222, characters 5-12", Bs_List.some(/* :: */[ 1, /* :: */[ 2, @@ -1125,7 +1227,7 @@ eq("File \"bs_list_test.ml\", line 211, characters 5-12", Bs_List.some(/* :: */[ ] ], mod2), /* true */1); -eq("File \"bs_list_test.ml\", line 212, characters 5-12", Bs_List.some(/* :: */[ +eq("File \"bs_list_test.ml\", line 223, characters 5-12", Bs_List.some(/* :: */[ 1, /* :: */[ 3, @@ -1136,16 +1238,16 @@ eq("File \"bs_list_test.ml\", line 212, characters 5-12", Bs_List.some(/* :: */[ ] ], mod2), /* false */0); -eq("File \"bs_list_test.ml\", line 213, characters 5-12", Bs_List.some(/* [] */0, mod2), /* false */0); +eq("File \"bs_list_test.ml\", line 224, characters 5-12", Bs_List.some(/* [] */0, mod2), /* false */0); -eq("File \"bs_list_test.ml\", line 214, characters 5-12", Bs_List.every2(/* [] */0, /* :: */[ +eq("File \"bs_list_test.ml\", line 225, characters 5-12", Bs_List.every2(/* [] */0, /* :: */[ 1, /* [] */0 ], (function (x, y) { return +(x > y); })), /* true */1); -eq("File \"bs_list_test.ml\", line 215, characters 5-12", Bs_List.every2(/* :: */[ +eq("File \"bs_list_test.ml\", line 226, characters 5-12", Bs_List.every2(/* :: */[ 2, /* [] */0 ], /* :: */[ @@ -1155,7 +1257,7 @@ eq("File \"bs_list_test.ml\", line 215, characters 5-12", Bs_List.every2(/* :: * return +(x > y); })), /* true */1); -eq("File \"bs_list_test.ml\", line 216, characters 5-12", Bs_List.every2(/* :: */[ +eq("File \"bs_list_test.ml\", line 227, characters 5-12", Bs_List.every2(/* :: */[ 2, /* :: */[ 3, @@ -1171,14 +1273,14 @@ eq("File \"bs_list_test.ml\", line 216, characters 5-12", Bs_List.every2(/* :: * return +(x > y); })), /* false */0); -eq("File \"bs_list_test.ml\", line 217, characters 5-12", Bs_List.some2(/* [] */0, /* :: */[ +eq("File \"bs_list_test.ml\", line 228, characters 5-12", Bs_List.some2(/* [] */0, /* :: */[ 1, /* [] */0 ], (function (x, y) { return +(x > y); })), /* false */0); -eq("File \"bs_list_test.ml\", line 218, characters 5-12", Bs_List.some2(/* :: */[ +eq("File \"bs_list_test.ml\", line 229, characters 5-12", Bs_List.some2(/* :: */[ 2, /* :: */[ 3, @@ -1194,7 +1296,7 @@ eq("File \"bs_list_test.ml\", line 218, characters 5-12", Bs_List.some2(/* :: */ return +(x > y); })), /* true */1); -eq("File \"bs_list_test.ml\", line 219, characters 5-12", Bs_List.some2(/* :: */[ +eq("File \"bs_list_test.ml\", line 230, characters 5-12", Bs_List.some2(/* :: */[ 0, /* :: */[ 3, @@ -1210,7 +1312,7 @@ eq("File \"bs_list_test.ml\", line 219, characters 5-12", Bs_List.some2(/* :: */ return +(x > y); })), /* false */0); -eq("File \"bs_list_test.ml\", line 220, characters 5-12", Bs_List.has(/* :: */[ +eq("File \"bs_list_test.ml\", line 231, characters 5-12", Bs_List.has(/* :: */[ 1, /* :: */[ 2, @@ -1223,7 +1325,7 @@ eq("File \"bs_list_test.ml\", line 220, characters 5-12", Bs_List.has(/* :: */[ return +("" + x === s); })), /* true */1); -eq("File \"bs_list_test.ml\", line 221, characters 5-12", Bs_List.has(/* :: */[ +eq("File \"bs_list_test.ml\", line 232, characters 5-12", Bs_List.has(/* :: */[ 1, /* :: */[ 2, @@ -1237,7 +1339,7 @@ eq("File \"bs_list_test.ml\", line 221, characters 5-12", Bs_List.has(/* :: */[ })), /* false */0); function makeTest(n) { - return eq("File \"bs_list_test.ml\", line 224, characters 5-12", Bs_List.make(n, 3), Bs_List.makeBy(n, (function () { + return eq("File \"bs_list_test.ml\", line 235, characters 5-12", Bs_List.make(n, 3), Bs_List.makeBy(n, (function () { return 3; }))); } @@ -1262,7 +1364,7 @@ var u1 = Bs_List.keepMap(u0, (function (x) { } })); -eq("File \"bs_list_test.ml\", line 235, characters 5-12", u1, /* :: */[ +eq("File \"bs_list_test.ml\", line 246, characters 5-12", u1, /* :: */[ 1, /* :: */[ 8, diff --git a/jscomp/test/bs_list_test.ml b/jscomp/test/bs_list_test.ml index b73c2ba186..6f58228789 100644 --- a/jscomp/test/bs_list_test.ml +++ b/jscomp/test/bs_list_test.ml @@ -39,12 +39,23 @@ let () = let (=~) = eq "FLATTEN" in - N.(concatMany + N.(flatten [[1]; [2]; [3];[]; makeBy 4 (fun [@bs] i -> i )] ) =~ [1;2;3; 0;1;2;3]; - N.concatMany [] =~ []; - N.concatMany [[];[]; [2]; [1];[2];[]] =~ [2;1;2] + N.flatten [] =~ []; + N.flatten [[];[]; [2]; [1];[2];[]] =~ [2;1;2] + +let () = + let (=~) = eq "CONCATMANY" in + N.(concatMany + [|[1]; [2]; [3];[]; makeBy 4 (fun [@bs] i -> i )|] + ) =~ + [1;2;3; 0;1;2;3]; + N.concatMany [||] =~ []; + N.concatMany [|[];[]; [2]; [1];[2];[]|] =~ [2;1;2]; + N.concatMany [|[];[]; [2;3]; [1];[2];[]|] =~ [2;3;1;2] + let () = eq __LOC__ @@ -93,10 +104,10 @@ let () = let () = let (=~) = eq "FILTER" in - N.keepBy [1;2;3;4] mod2 =~ [2;4]; - N.keepBy [1;3;41] mod2 =~ []; - N.keepBy [] mod2 =~ []; - N.keepBy [2;2;2;4;6] mod2 =~ [2;2;2;4;6] + N.keep [1;2;3;4] mod2 =~ [2;4]; + N.keep [1;3;41] mod2 =~ []; + N.keep [] mod2 =~ []; + N.keep [2;2;2;4;6] mod2 =~ [2;2;2;4;6] let id : int -> int [@bs] = fun [@bs] x -> x let () = diff --git a/jscomp/test/bs_map_set_dict_test.ml b/jscomp/test/bs_map_set_dict_test.ml index e01997c5d6..667fe84200 100644 --- a/jscomp/test/bs_map_set_dict_test.ml +++ b/jscomp/test/bs_map_set_dict_test.ml @@ -19,15 +19,15 @@ module MI = Bs.MapInt module I = Array_data_util module A = Bs_Array module L = Bs.List -let m0 : (_,string,_) M.t = M.empty (module Icmp) +let m0 : (_,string,_) M.t = M.make (module Icmp) module I2 = (val Bs.Dict.comparable ~cmp:(fun [@bs] (x : int) y -> compare y x )) -let m = M.empty (module Icmp2) -let m2 : (int, string, _) M.t = M.empty (module I2) +let m = M.make (module Icmp2) +let m2 : (int, string, _) M.t = M.make (module I2) let vv = MI.empty let vv2 = MI.empty module Md0 = Bs.MapDict @@ -52,13 +52,13 @@ let () = Md0.set ~cmp:Icmp.cmp m 1 1 in - let _m20 = M.empty (module Icmp) in + let _m20 = M.make (module Icmp) in Js.log m11 module S0 = Bs.SetDict let () = let count = 100_000 in - let v = ISet.empty (module Icmp2) in + let v = ISet.make (module Icmp2) in let m_dict = M.getDict m in let module M = (val m_dict) in let cmp = M.cmp in diff --git a/jscomp/test/bs_mutable_set_test.js b/jscomp/test/bs_mutable_set_test.js index ac3cac0622..b27654e157 100644 --- a/jscomp/test/bs_mutable_set_test.js +++ b/jscomp/test/bs_mutable_set_test.js @@ -379,11 +379,11 @@ var a0 = { data: Bs_internalSetInt.ofArray(xs$24) }; -var a1 = Bs_SetIntM.keepBy(a0, (function (x) { +var a1 = Bs_SetIntM.keep(a0, (function (x) { return +(x % 2 === 0); })); -var a2 = Bs_SetIntM.keepBy(a0, (function (x) { +var a2 = Bs_SetIntM.keep(a0, (function (x) { return +(x % 2 !== 0); })); @@ -599,7 +599,7 @@ var v$5 = { data: Bs_internalSetInt.ofArray(xs$26) }; -var copyV = Bs_SetIntM.keepBy(v$5, (function (x) { +var copyV = Bs_SetIntM.keep(v$5, (function (x) { return +(x % 8 === 0); })); @@ -607,7 +607,7 @@ var match$5 = Bs_SetIntM.partition(v$5, (function (x) { return +(x % 8 === 0); })); -var cc$1 = Bs_SetIntM.keepBy(v$5, (function (x) { +var cc$1 = Bs_SetIntM.keep(v$5, (function (x) { return +(x % 8 !== 0); })); @@ -834,7 +834,7 @@ var A = 0; var L = 0; -var empty = Bs_SetIntM.empty; +var empty = Bs_SetIntM.make; var ofArray = Bs_SetIntM.ofArray; diff --git a/jscomp/test/bs_mutable_set_test.ml b/jscomp/test/bs_mutable_set_test.ml index 5999810133..f2f203f553 100644 --- a/jscomp/test/bs_mutable_set_test.ml +++ b/jscomp/test/bs_mutable_set_test.ml @@ -10,7 +10,7 @@ module R = Bs.Range module A = Bs.Array module L = Bs.List let (++) = A.concat -let empty = N.empty +let empty = N.make let ofArray = N.ofArray (************************************************) @@ -157,8 +157,8 @@ let () = let a0 = ofArray (I.randomRange 0 1000) in let a1,a2 = ( - N.keepBy a0 (fun [@bs] x -> x mod 2 = 0), - N.keepBy a0 (fun [@bs] x -> x mod 2 <> 0) + N.keep a0 (fun [@bs] x -> x mod 2 = 0), + N.keep a0 (fun [@bs] x -> x mod 2 <> 0) ) in let a3, a4 = N.partition a0 (fun [@bs] x -> x mod 2 = 0) in b __LOC__ (N.eq a1 a3); @@ -169,7 +169,7 @@ let () = (************************************************) let () = - let v = N.empty () in + let v = N.make () in for i = 0 to 1_00_000 do (* [%assert (N.checkInvariantInternal !v)]; *) N.add v i @@ -182,7 +182,7 @@ let () = let () = let u = I.randomRange 30 100 ++ I.randomRange 40 120 in - let v = N.empty () in + let v = N.make () in N.mergeMany v u ; eq __LOC__ (N.size v) 91 ; eq __LOC__ (N.toArray v) (I.range 30 120) @@ -241,9 +241,9 @@ let () = let () = let v = N.ofArray (I.randomRange 0 1000) in - let copyV = N.keepBy v (fun[@bs] x -> x mod 8 = 0) in + let copyV = N.keep v (fun[@bs] x -> x mod 8 = 0) in let aa,bb = N.partition v (fun[@bs] x -> x mod 8 = 0) in - let cc = N.keepBy v (fun[@bs] x -> x mod 8 <> 0) in + let cc = N.keep v (fun[@bs] x -> x mod 8 <> 0) in for i = 0 to 200 do N.remove v i done ; @@ -283,13 +283,13 @@ let () = (N.intersect (f @@ I.randomRange 0 20) (f @@ I.randomRange 21 40) - =~ (N.empty ()) + =~ (N.make ()) ); b __LOC__ (N.intersect (f @@ I.randomRange 21 40) (f @@ I.randomRange 0 20) - =~ (N.empty ()) + =~ (N.make ()) ); b __LOC__ (N.intersect diff --git a/jscomp/test/bs_poly_map_test.ml b/jscomp/test/bs_poly_map_test.ml index 592c199c85..dfa8001e57 100644 --- a/jscomp/test/bs_poly_map_test.ml +++ b/jscomp/test/bs_poly_map_test.ml @@ -18,7 +18,7 @@ module I = Array_data_util let mapOfArray x = M.ofArray ~dict:(module Icmp) x let setOfArray x = N.ofArray ~dict:(module Icmp) x -let emptyMap () = M.empty (module Icmp) +let emptyMap () = M.make (module Icmp) let mergeInter s1 s2 = setOfArray @@ M.keysToArray (M.merge s1 s2 (fun[@bs] k v1 v2 -> diff --git a/jscomp/test/bs_poly_mutable_set_test.js b/jscomp/test/bs_poly_mutable_set_test.js index a982591646..cfc1bd5991 100644 --- a/jscomp/test/bs_poly_mutable_set_test.js +++ b/jscomp/test/bs_poly_mutable_set_test.js @@ -287,11 +287,11 @@ b("File \"bs_poly_mutable_set_test.ml\", line 147, characters 4-11", Bs_SetM.eq( var a0 = ofArray(Array_data_util.randomRange(0, 1000)); -var a1 = Bs_SetM.keepBy(a0, (function (x) { +var a1 = Bs_SetM.keep(a0, (function (x) { return +(x % 2 === 0); })); -var a2 = Bs_SetM.keepBy(a0, (function (x) { +var a2 = Bs_SetM.keep(a0, (function (x) { return +(x % 2 !== 0); })); diff --git a/jscomp/test/bs_poly_mutable_set_test.ml b/jscomp/test/bs_poly_mutable_set_test.ml index 4c7fd9f978..9fa8cde52a 100644 --- a/jscomp/test/bs_poly_mutable_set_test.ml +++ b/jscomp/test/bs_poly_mutable_set_test.ml @@ -10,7 +10,7 @@ module IntCmp = (val Bs.Dict.comparable (fun[@bs] (x:int) y -> compare x y)) module L = Bs.List let ofArray = N.ofArray ~dict:(module IntCmp) -let empty () = N.empty ~dict:(module IntCmp) +let empty () = N.make ~dict:(module IntCmp) let () = @@ -155,8 +155,8 @@ let () = let a0 = ofArray (I.randomRange 0 1000) in let a1,a2 = ( - N.keepBy a0 (fun [@bs] x -> x mod 2 = 0), - N.keepBy a0 (fun [@bs] x -> x mod 2 <> 0) + N.keep a0 (fun [@bs] x -> x mod 2 = 0), + N.keep a0 (fun [@bs] x -> x mod 2 <> 0) ) in let a3, a4 = N.partition a0 (fun [@bs] x -> x mod 2 = 0) in b __LOC__ (N.eq a1 a3); diff --git a/jscomp/test/bs_poly_set_test.js b/jscomp/test/bs_poly_set_test.js index 4a28c397d1..f2b6835517 100644 --- a/jscomp/test/bs_poly_set_test.js +++ b/jscomp/test/bs_poly_set_test.js @@ -247,11 +247,11 @@ b("File \"bs_poly_set_test.ml\", line 101, characters 4-11", +(Bs_Set.cmp(u0$1, var a0 = Bs_Set.ofArray(Array_data_util.randomRange(0, 1000), IntCmp); -var a1 = Bs_Set.keepBy(a0, (function (x) { +var a1 = Bs_Set.keep(a0, (function (x) { return +(x % 2 === 0); })); -var a2 = Bs_Set.keepBy(a0, (function (x) { +var a2 = Bs_Set.keep(a0, (function (x) { return +(x % 2 !== 0); })); @@ -344,7 +344,7 @@ b("File \"bs_poly_set_test.ml\", line 130, characters 4-11", Bs_List.every(/* :: var a = Bs_Set.ofArray(/* int array */[], IntCmp); -var m$4 = Bs_Set.keepBy(a, (function (x) { +var m$4 = Bs_Set.keep(a, (function (x) { return +(x % 2 === 0); })); diff --git a/jscomp/test/bs_poly_set_test.ml b/jscomp/test/bs_poly_set_test.ml index 595b449f9c..023087a6f8 100644 --- a/jscomp/test/bs_poly_set_test.ml +++ b/jscomp/test/bs_poly_set_test.ml @@ -77,10 +77,10 @@ let () = b __LOC__ (None = (N.get u22 59)); let u25 = N.add u22 59 in eq __LOC__ (N.size u25) 60; - b __LOC__ (N.minimum (N.empty (module IntCmp)) = None); - b __LOC__ (N.maximum (N.empty (module IntCmp)) = None); - b __LOC__ (N.minUndefined (N.empty (module IntCmp)) = Js.undefined); - b __LOC__ (N.maxUndefined (N.empty (module IntCmp)) = Js.undefined) + b __LOC__ (N.minimum (N.make (module IntCmp)) = None); + b __LOC__ (N.maximum (N.make (module IntCmp)) = None); + b __LOC__ (N.minUndefined (N.make (module IntCmp)) = Js.undefined); + b __LOC__ (N.maxUndefined (N.make (module IntCmp)) = Js.undefined) let testIterToList xs = let v = ref [] in @@ -104,8 +104,8 @@ let () = let a0 = N.ofArray ~dict:(module IntCmp) (I.randomRange 0 1000) in let a1,a2 = ( - N.keepBy a0 (fun [@bs] x -> x mod 2 = 0), - N.keepBy a0 (fun [@bs] x -> x mod 2 <> 0) + N.keep a0 (fun [@bs] x -> x mod 2 = 0), + N.keep a0 (fun [@bs] x -> x mod 2 <> 0) ) in let a3, a4 = N.partition a0 (fun [@bs] x -> x mod 2 = 0) in b __LOC__ (N.eq a1 a3); @@ -132,10 +132,10 @@ let () = let () = let a = N.ofArray ~dict:(module IntCmp) [||] in - b __LOC__ (N.isEmpty (N.keepBy a (fun[@bs] x -> x mod 2 = 0))) + b __LOC__ (N.isEmpty (N.keep a (fun[@bs] x -> x mod 2 = 0))) let () = - let (aa,bb), pres = N.split (N.empty ~dict:(module IntCmp)) 0 in + let (aa,bb), pres = N.split (N.make ~dict:(module IntCmp)) 0 in b __LOC__ (N.isEmpty aa); b __LOC__ (N.isEmpty bb); b __LOC__ (not pres) diff --git a/lib/js/bs_Array.js b/lib/js/bs_Array.js index 9fd5665289..fff827762d 100644 --- a/lib/js/bs_Array.js +++ b/lib/js/bs_Array.js @@ -255,7 +255,7 @@ function map(a, f) { return r; } -function keepBy(a, f) { +function keep(a, f) { var l = a.length; var r = new Array(l); var j = 0; @@ -480,7 +480,7 @@ exports.ofList = ofList; exports.forEach = forEach; exports.map = map; exports.zipBy = zipBy; -exports.keepBy = keepBy; +exports.keep = keep; exports.keepMap = keepMap; exports.forEachWithIndex = forEachWithIndex; exports.mapWithIndex = mapWithIndex; diff --git a/lib/js/bs_List.js b/lib/js/bs_List.js index d72435a14f..422c975340 100644 --- a/lib/js/bs_List.js +++ b/lib/js/bs_List.js @@ -669,7 +669,7 @@ function flattenAux(_prec, _xs) { }; } -function concatMany(_xs) { +function flatten(_xs) { while(true) { var xs = _xs; if (xs) { @@ -692,6 +692,24 @@ function concatMany(_xs) { }; } +function concatMany(xs) { + var len = xs.length; + if (len !== 1) { + if (len !== 0) { + var len$1 = xs.length; + var v = xs[len$1 - 1 | 0]; + for(var i = len$1 - 2 | 0; i >= 0; --i){ + v = concat(xs[i], v); + } + return v; + } else { + return /* [] */0; + } + } else { + return xs[0]; + } +} + function mapReverse(l, f) { var f$1 = f; var _accu = /* [] */0; @@ -1137,7 +1155,7 @@ function getBy(_xs, p) { }; } -function keepBy(_xs, p) { +function keep(_xs, p) { while(true) { var xs = _xs; if (xs) { @@ -1282,6 +1300,7 @@ exports.size = size; exports.toArray = toArray; exports.reverseConcat = reverseConcat; exports.reverse = reverse; +exports.flatten = flatten; exports.concatMany = concatMany; exports.mapReverse = mapReverse; exports.forEach = forEach; @@ -1307,7 +1326,7 @@ exports.hasAssocByReference = hasAssocByReference; exports.removeAssoc = removeAssoc; exports.removeAssocByReference = removeAssocByReference; exports.getBy = getBy; -exports.keepBy = keepBy; +exports.keep = keep; exports.keepMap = keepMap; exports.partition = partition; exports.unzip = unzip; diff --git a/lib/js/bs_Map.js b/lib/js/bs_Map.js index 0beaddee83..de37537055 100644 --- a/lib/js/bs_Map.js +++ b/lib/js/bs_Map.js @@ -112,10 +112,10 @@ function some(m, f) { return Bs_MapDict.some(m.data, f); } -function keepBy(m, f) { +function keep(m, f) { return { cmp: m.cmp, - data: Bs_MapDict.keepBy(m.data, f) + data: Bs_MapDict.keep(m.data, f) }; } @@ -286,7 +286,7 @@ exports.set = set; exports.update = update; exports.merge = merge; exports.mergeMany = mergeMany; -exports.keepBy = keepBy; +exports.keep = keep; exports.partition = partition; exports.split = split; exports.map = map; diff --git a/lib/js/bs_MapDict.js b/lib/js/bs_MapDict.js index c57a7c482c..4465e8d286 100644 --- a/lib/js/bs_MapDict.js +++ b/lib/js/bs_MapDict.js @@ -325,7 +325,7 @@ var getExn = Bs_internalAVLtree.getExn; var checkInvariantInternal = Bs_internalAVLtree.checkInvariantInternal; -var keepBy = Bs_internalAVLtree.filterShared; +var keep = Bs_internalAVLtree.filterShared; var partition = Bs_internalAVLtree.partitionShared; @@ -367,7 +367,7 @@ exports.set = set; exports.update = update; exports.merge = merge; exports.mergeMany = mergeMany; -exports.keepBy = keepBy; +exports.keep = keep; exports.partition = partition; exports.split = split; exports.map = map; diff --git a/lib/js/bs_MapInt.js b/lib/js/bs_MapInt.js index 38a0a431ed..446c375e8b 100644 --- a/lib/js/bs_MapInt.js +++ b/lib/js/bs_MapInt.js @@ -214,7 +214,7 @@ var getExn = Bs_internalMapInt.getExn; var merge = Bs_internalMapInt.merge; -var keepBy = Bs_internalAVLtree.filterShared; +var keep = Bs_internalAVLtree.filterShared; var partition = Bs_internalAVLtree.partitionShared; @@ -259,7 +259,7 @@ exports.set = set; exports.update = update; exports.mergeArray = mergeArray; exports.merge = merge; -exports.keepBy = keepBy; +exports.keep = keep; exports.partition = partition; exports.split = split; exports.map = map; diff --git a/lib/js/bs_MapString.js b/lib/js/bs_MapString.js index 5a45ee9b1d..3999242800 100644 --- a/lib/js/bs_MapString.js +++ b/lib/js/bs_MapString.js @@ -214,7 +214,7 @@ var getExn = Bs_internalMapString.getExn; var merge = Bs_internalMapString.merge; -var keepBy = Bs_internalAVLtree.filterShared; +var keep = Bs_internalAVLtree.filterShared; var partition = Bs_internalAVLtree.partitionShared; @@ -259,7 +259,7 @@ exports.set = set; exports.update = update; exports.mergeArray = mergeArray; exports.merge = merge; -exports.keepBy = keepBy; +exports.keep = keep; exports.partition = partition; exports.split = split; exports.map = map; diff --git a/lib/js/bs_Set.js b/lib/js/bs_Set.js index dbcae2f17b..000133a6eb 100644 --- a/lib/js/bs_Set.js +++ b/lib/js/bs_Set.js @@ -138,10 +138,10 @@ function some(m, f) { return Bs_SetDict.some(m.data, f); } -function keepBy(m, f) { +function keep(m, f) { return { cmp: m.cmp, - data: Bs_SetDict.keepBy(m.data, f) + data: Bs_SetDict.keep(m.data, f) }; } @@ -254,7 +254,7 @@ exports.forEach = forEach; exports.reduce = reduce; exports.every = every; exports.some = some; -exports.keepBy = keepBy; +exports.keep = keep; exports.partition = partition; exports.size = size; exports.toList = toList; diff --git a/lib/js/bs_SetDict.js b/lib/js/bs_SetDict.js index 7bd595e916..dcb9dd5f9c 100644 --- a/lib/js/bs_SetDict.js +++ b/lib/js/bs_SetDict.js @@ -290,7 +290,7 @@ var every = Bs_internalAVLset.every; var some = Bs_internalAVLset.some; -var keepBy = Bs_internalAVLset.filterShared; +var keep = Bs_internalAVLset.filterShared; var partition = Bs_internalAVLset.partitionShared; @@ -335,7 +335,7 @@ exports.forEach = forEach; exports.reduce = reduce; exports.every = every; exports.some = some; -exports.keepBy = keepBy; +exports.keep = keep; exports.partition = partition; exports.size = size; exports.toList = toList; diff --git a/lib/js/bs_SetInt.js b/lib/js/bs_SetInt.js index 762c09a8a2..32f08f9c5d 100644 --- a/lib/js/bs_SetInt.js +++ b/lib/js/bs_SetInt.js @@ -283,7 +283,7 @@ var every = Bs_internalAVLset.every; var some = Bs_internalAVLset.some; -var keepBy = Bs_internalAVLset.filterShared; +var keep = Bs_internalAVLset.filterShared; var partition = Bs_internalAVLset.partitionShared; @@ -328,7 +328,7 @@ exports.forEach = forEach; exports.reduce = reduce; exports.every = every; exports.some = some; -exports.keepBy = keepBy; +exports.keep = keep; exports.partition = partition; exports.size = size; exports.toList = toList; diff --git a/lib/js/bs_SetIntM.js b/lib/js/bs_SetIntM.js index 685a5f3864..2ed7870798 100644 --- a/lib/js/bs_SetIntM.js +++ b/lib/js/bs_SetIntM.js @@ -312,7 +312,7 @@ function split(d, key) { } } -function keepBy(d, p) { +function keep(d, p) { return { data: Bs_internalAVLset.filterCopy(d.data, p) }; @@ -468,7 +468,7 @@ exports.forEach = forEach; exports.reduce = reduce; exports.every = every; exports.some = some; -exports.keepBy = keepBy; +exports.keep = keep; exports.partition = partition; exports.size = size; exports.toList = toList; diff --git a/lib/js/bs_SetM.js b/lib/js/bs_SetM.js index d868ca9a6b..4a1f47cd85 100644 --- a/lib/js/bs_SetM.js +++ b/lib/js/bs_SetM.js @@ -327,7 +327,7 @@ function split(d, key) { } } -function keepBy(d, p) { +function keep(d, p) { return { cmp: d.cmp, data: Bs_internalAVLset.filterCopy(d.data, p) @@ -507,7 +507,7 @@ exports.forEach = forEach; exports.reduce = reduce; exports.every = every; exports.some = some; -exports.keepBy = keepBy; +exports.keep = keep; exports.partition = partition; exports.size = size; exports.toList = toList; diff --git a/lib/js/bs_SetString.js b/lib/js/bs_SetString.js index f87f6ca191..ee9bfe2dee 100644 --- a/lib/js/bs_SetString.js +++ b/lib/js/bs_SetString.js @@ -283,7 +283,7 @@ var every = Bs_internalAVLset.every; var some = Bs_internalAVLset.some; -var keepBy = Bs_internalAVLset.filterShared; +var keep = Bs_internalAVLset.filterShared; var partition = Bs_internalAVLset.partitionShared; @@ -328,7 +328,7 @@ exports.forEach = forEach; exports.reduce = reduce; exports.every = every; exports.some = some; -exports.keepBy = keepBy; +exports.keep = keep; exports.partition = partition; exports.size = size; exports.toList = toList; diff --git a/lib/js/bs_SetStringM.js b/lib/js/bs_SetStringM.js index 3f2fc50d41..5cc93a510d 100644 --- a/lib/js/bs_SetStringM.js +++ b/lib/js/bs_SetStringM.js @@ -312,7 +312,7 @@ function split(d, key) { } } -function keepBy(d, p) { +function keep(d, p) { return { data: Bs_internalAVLset.filterCopy(d.data, p) }; @@ -468,7 +468,7 @@ exports.forEach = forEach; exports.reduce = reduce; exports.every = every; exports.some = some; -exports.keepBy = keepBy; +exports.keep = keep; exports.partition = partition; exports.size = size; exports.toList = toList; From 12f3f940da5df2ce591c15ff453e70a8855f5328 Mon Sep 17 00:00:00 2001 From: Hongbo Zhang Date: Thu, 1 Feb 2018 13:46:54 +0800 Subject: [PATCH 5/6] reduce the number of exposed toplevel modules --- jscomp/others/bs.ml | 98 ++++++++++++--------------- jscomp/others/bs_HashSet.ml | 6 +- jscomp/others/bs_HashSet.mli | 10 ++- jscomp/others/bs_Map.ml | 97 ++++++++++++++------------ jscomp/others/bs_Map.mli | 16 ++++- jscomp/others/bs_Set.ml | 75 ++++++++++---------- jscomp/others/bs_Set.mli | 13 +++- jscomp/others/bs_SetM.ml | 4 +- jscomp/others/bs_SetM.mli | 11 ++- jscomp/others/bs_SortArray.ml | 7 +- jscomp/others/bs_SortArray.mli | 9 ++- jscomp/test/bs_MapInt_test.js | 5 +- jscomp/test/bs_MapInt_test.ml | 12 ++-- jscomp/test/bs_hashmap_test.ml | 2 +- jscomp/test/bs_hashset_int_test.ml | 4 +- jscomp/test/bs_hashtbl_string_test.ml | 14 ++-- jscomp/test/bs_map_set_dict_test.ml | 6 +- jscomp/test/bs_set_bench.ml | 2 +- jscomp/test/bs_set_int_test.ml | 2 +- jscomp/test/imm_map_bench.ml | 2 +- lib/js/bs.js | 60 ++-------------- lib/js/bs_HashSet.js | 12 ++-- lib/js/bs_Map.js | 7 +- lib/js/bs_Set.js | 7 +- lib/js/bs_SetM.js | 4 +- lib/js/bs_SortArray.js | 4 +- 26 files changed, 249 insertions(+), 240 deletions(-) diff --git a/jscomp/others/bs.ml b/jscomp/others/bs.ml index a861299e59..4d3bcab0bb 100644 --- a/jscomp/others/bs.ml +++ b/jscomp/others/bs.ml @@ -34,75 +34,65 @@ module List = Bs_List module MutableStack = Bs_Stack module Range = Bs_Range -(** Immutable sorted set *) +(** {!Bs.Set} + The toplevel provides generic immutable set operations. + It also has three specialized inner modules + {!Bs.Set.Int} and {!Bs.Set.String} + {!Bs.Set.Dict}: This module separate date from function + which is more verbbose but slightly more efficient + +*) module Set = Bs_Set -(** The implementation detail for {!Bs.Set}, also slightly more efficient, - can also be accessed via {!Bs.Set.Dict} *) -module SetDict = Bs_SetDict -(** can also be accessed via {!Bs.Set.Int}*) -module SetInt = Bs_SetInt - -(** can also be accessed via {!Bs.Set.String}*) -module SetString = Bs_SetString - - -module MutableSet = Bs_SetM - -(** can also be accessed via {!Bs.MutableSet.Int}*) -module MutableSetInt = Bs_SetIntM - -(** can also be accessed via {!Bs.MutableSet.String}*) -module MutableSetString = Bs_SetIntM - - -module UnorderedMutableSet = Bs_HashSet - -(** can also be accessed via {!Bs.UnordedMutableSet.Int}*) -module UnorderedMutableSetInt = Bs_HashSetInt - -(** can also be accessed via {!Bs.UnordedMutableSet.String}*) -module UnorderedMutableSetString = Bs_HashSetString - - +(** {!Bs.Map}, + The toplevel provides generic immutable map operations. + It also has three specialized inner modules + {!Bs.Map.Int} and {!Bs.Map.String} + {!Bs.Map.Dict}: This module separate date from function + which is more verbbose but slightly more efficient +*) module Map = Bs_Map -(** The implementaion detail for {!Bs.Map}, also slightly more efficient, - can also be accessed via {!Bs.Map.Dict}*) -module MapDict = Bs_MapDict - -(** can also be accessed via {!Bs.Map.Int}*) -module MapInt = Bs_MapInt -(** can also be accessed via {!Bs.Map.String}*) -module MapString = Bs_MapString +(** {!Bs.MutableSet} + The toplevel provides generic mutable set operations. + It also has two specialized inner modules + {!Bs.MutableSet.Int} and {!Bs.MutableSet.String} +*) +module MutableSet = Bs_SetM +(** {!Bs.MutableMap} + The toplevel provides generic mutable map operations. + It also has two specialized inner modules + {!Bs.MutableMap.Int} and {!Bs.MutableMap.String} +*) module MutableMap = Bs_MapM -(** can also be accessed via {!Bs.MutableMap.Int}*) -module MutableMapInt = Bs_MapIntM -(** can also be accessed via {!Bs.MutableMap.String}*) -module MutableMapString = Bs_MapStringM +(** {!Bs.HashSet} + The toplevel provides generic mutable hash set operations. + It also has two specialized inner modules + {!Bs.HashSet.Int} and {!Bs.HashSet.String} +*) +module HashSet = Bs_HashSet - -module UnorderedMutableMap = Bs_HashMap - -(** can also be accessed via {!Bs.UnorderedMutableMap.Int}*) -module UnorderedMutableMapInt = Bs_HashMapInt - -(** can also be accessed via {!Bs.UnorderedMutableMap.String}*) -module UnorderedMutableMapString = Bs_HashMapString +(** {!Bs.HashMap} + The toplevel provides generic mutable hash map operations. + It also has two specialized inner modules + {!Bs.HashMap.Int} and {!Bs.HashMap.String} +*) +module HashMap = Bs_HashMap + +(** {!Bs.SortArray} + The toplevel provides some generic sort related utililties. + It also has two specialized inner modules + {!Bs.SortArray.Int} and {!Bs.SortArray.String} +*) module SortArray = Bs_SortArray -(** can also be accessed via {!Bs.SortArray.Int}*) -module SortArrayInt = Bs_SortArrayInt - -(** can also be accessed via {!Bs.SortArray.String}*) -module SortArrayString = Bs_SortArrayString diff --git a/jscomp/others/bs_HashSet.ml b/jscomp/others/bs_HashSet.ml index 20c552eade..4440943a7f 100644 --- a/jscomp/others/bs_HashSet.ml +++ b/jscomp/others/bs_HashSet.ml @@ -22,6 +22,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) +module Int = Bs_HashSetInt + +module String = Bs_HashSetString + module N = Bs_internalSetBuckets module C = Bs_internalBucketsType @@ -189,5 +193,3 @@ let mergeMany h arr = done -module Int = Bs_HashSetInt -module String = Bs_HashSetString diff --git a/jscomp/others/bs_HashSet.mli b/jscomp/others/bs_HashSet.mli index 99454fcc48..94fe2448ef 100644 --- a/jscomp/others/bs_HashSet.mli +++ b/jscomp/others/bs_HashSet.mli @@ -22,7 +22,14 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) +(** specalized when key type is [int], more efficient + than the gerneic type *) +module Int = Bs_HashSetInt +(** specalized when key type is [string], more efficient + than the gerneic type *) +module String = Bs_HashSetString + type ('a, 'id) t (** The type of hash tables from type ['a] to type ['b]. *) @@ -59,5 +66,4 @@ val mergeMany: ('a,'id) t -> 'a array -> unit val getBucketHistogram: _ t -> int array -module Int = Bs_HashSetInt -module String = Bs_HashSetString + diff --git a/jscomp/others/bs_Map.ml b/jscomp/others/bs_Map.ml index 70f08b6160..59854dec03 100644 --- a/jscomp/others/bs_Map.ml +++ b/jscomp/others/bs_Map.ml @@ -12,6 +12,19 @@ (***********************************************************************) (** Adapted by authors of BuckleScript without using functors *) +(** specalized when key type is [int], more efficient + than the gerneic type +*) +module Int = Bs_MapInt +(** specalized when key type is [string], more efficient + than the gerneic type *) +module String = Bs_MapString + +(** seprate function from data, a more verbsoe but slightly + more efficient +*) +module Dict = Bs_MapDict + module N = Bs_MapDict module A = Bs_Array @@ -20,7 +33,7 @@ type ('key, 'id ) cmp = ('key, 'id) Bs_Dict.cmp module S = struct type ('k,'v,'id) t = { cmp: ('k,'id) cmp; - data: ('k,'v, 'id) N.t + data: ('k,'v, 'id) Dict.t } [@@bs.deriving abstract] end @@ -30,108 +43,108 @@ type ('k, 'v, 'id ) t = ('k, 'v, 'id) S.t let ofArray (type k) (type id) data ~(dict : (k,id) dict) = let module M = (val dict) in let cmp = M.cmp in - S.t ~cmp ~data:(N.ofArray ~cmp data) + S.t ~cmp ~data:(Dict.ofArray ~cmp data) let remove m x = let cmp, odata = S.cmp m, S.data m in - let newData = N.remove odata x ~cmp in + let newData = Dict.remove odata x ~cmp in if newData == odata then m else S.t ~cmp ~data:newData let removeMany m x = let cmp, odata = S.cmp m, S.data m in - let newData = N.removeMany odata x ~cmp in + let newData = Dict.removeMany odata x ~cmp in S.t ~cmp ~data:newData let set m key d = let cmp = S.cmp m in - S.t ~cmp ~data:(N.set ~cmp (S.data m) key d) + S.t ~cmp ~data:(Dict.set ~cmp (S.data m) key d) let mergeMany m e = let cmp = S.cmp m in - S.t ~cmp ~data:(N.mergeMany ~cmp (S.data m) e) + S.t ~cmp ~data:(Dict.mergeMany ~cmp (S.data m) e) let update m key f = let cmp = S.cmp m in - S.t ~cmp ~data:(N.update ~cmp (S.data m) key f ) + S.t ~cmp ~data:(Dict.update ~cmp (S.data m) key f ) let split m x = let cmp = S.cmp m in - let (l,r),b = N.split ~cmp (S.data m) x in + let (l,r),b = Dict.split ~cmp (S.data m) x in (S.t ~cmp ~data:l, S.t ~cmp ~data:r), b let merge s1 s2 f = let cmp = S.cmp s1 in - S.t ~cmp ~data:(N.merge ~cmp (S.data s1) (S.data s2) f) + S.t ~cmp ~data:(Dict.merge ~cmp (S.data s1) (S.data s2) f) let make (type elt) (type id) ~(dict: (elt, id) dict) = let module M = (val dict) in - S.t ~cmp:M.cmp ~data:N.empty + S.t ~cmp:M.cmp ~data:Dict.empty let isEmpty map = - N.isEmpty (S.data map) + Dict.isEmpty (S.data map) -let forEach m f = N.forEach (S.data m) f +let forEach m f = Dict.forEach (S.data m) f -let reduce m acc f = N.reduce (S.data m) acc f +let reduce m acc f = Dict.reduce (S.data m) acc f -let every m f = N.every (S.data m) f +let every m f = Dict.every (S.data m) f -let some m f = N.some (S.data m) f +let some m f = Dict.some (S.data m) f let keep m f = - S.t ~cmp:(S.cmp m) ~data:(N.keep (S.data m) f) + S.t ~cmp:(S.cmp m) ~data:(Dict.keep (S.data m) f) let partition m p = let cmp = S.cmp m in - let l,r = N.partition (S.data m) p in + let l,r = Dict.partition (S.data m) p in S.t ~cmp ~data:l, S.t ~cmp ~data:r let map m f = - S.t ~cmp:(S.cmp m) ~data:(N.map (S.data m) f) + S.t ~cmp:(S.cmp m) ~data:(Dict.map (S.data m) f) let mapWithKey m f = - S.t ~cmp:(S.cmp m) ~data:(N.mapWithKey (S.data m) f) - -let size map = N.size (S.data map) -let toList map = N.toList (S.data map) -let toArray m = N.toArray (S.data m) -let keysToArray m = N.keysToArray (S.data m) -let valuesToArray m = N.valuesToArray (S.data m) -let minKey m = N.minKey (S.data m) -let minKeyUndefined m = N.minKeyUndefined (S.data m) -let maxKey m = N.maxKey (S.data m) -let maxKeyUndefined m = N.maxKeyUndefined (S.data m) -let minimum m = N.minimum (S.data m) -let minUndefined m = N.minUndefined (S.data m) -let maximum m = N.maximum (S.data m) -let maxUndefined m = N.maxUndefined (S.data m) + S.t ~cmp:(S.cmp m) ~data:(Dict.mapWithKey (S.data m) f) + +let size map = Dict.size (S.data map) +let toList map = Dict.toList (S.data map) +let toArray m = Dict.toArray (S.data m) +let keysToArray m = Dict.keysToArray (S.data m) +let valuesToArray m = Dict.valuesToArray (S.data m) +let minKey m = Dict.minKey (S.data m) +let minKeyUndefined m = Dict.minKeyUndefined (S.data m) +let maxKey m = Dict.maxKey (S.data m) +let maxKeyUndefined m = Dict.maxKeyUndefined (S.data m) +let minimum m = Dict.minimum (S.data m) +let minUndefined m = Dict.minUndefined (S.data m) +let maximum m = Dict.maximum (S.data m) +let maxUndefined m = Dict.maxUndefined (S.data m) let get map x = - N.get ~cmp:(S.cmp map) (S.data map) x + Dict.get ~cmp:(S.cmp map) (S.data map) x let getUndefined map x = - N.getUndefined ~cmp:(S.cmp map) (S.data map) x + Dict.getUndefined ~cmp:(S.cmp map) (S.data map) x let getWithDefault map x def = - N.getWithDefault ~cmp:(S.cmp map) (S.data map) x def + Dict.getWithDefault ~cmp:(S.cmp map) (S.data map) x def let getExn map x = - N.getExn ~cmp:(S.cmp map) (S.data map) x + Dict.getExn ~cmp:(S.cmp map) (S.data map) x let has map x = - N.has ~cmp:(S.cmp map) (S.data map) x + Dict.has ~cmp:(S.cmp map) (S.data map) x let checkInvariantInternal m = - N.checkInvariantInternal (S.data m) + Dict.checkInvariantInternal (S.data m) let eq m1 m2 veq = - N.eq ~kcmp:(S.cmp m1) ~veq (S.data m1) (S.data m2) + Dict.eq ~kcmp:(S.cmp m1) ~veq (S.data m1) (S.data m2) let cmp m1 m2 vcmp = - N.cmp ~kcmp:(S.cmp m1) ~vcmp (S.data m1) (S.data m2) + Dict.cmp ~kcmp:(S.cmp m1) ~vcmp (S.data m1) (S.data m2) let getData = S.data @@ -147,5 +160,3 @@ let packDictData (type elt) (type id) ~(dict : (elt, id) dict) ~data = let module M = (val dict) in S.t ~cmp:M.cmp ~data -module Int = Bs_MapInt -module String = Bs_MapString diff --git a/jscomp/others/bs_Map.mli b/jscomp/others/bs_Map.mli index 2b873a80b9..39864a9aae 100644 --- a/jscomp/others/bs_Map.mli +++ b/jscomp/others/bs_Map.mli @@ -13,6 +13,20 @@ (** Adapted by authors of BuckleScript without using functors *) +(** specalized when key type is [int], more efficient + than the gerneic type +*) +module Int = Bs_MapInt +(** specalized when key type is [string], more efficient + than the gerneic type *) +module String = Bs_MapString + +(** seprate function from data, a more verbsoe but slightly + more efficient +*) +module Dict = Bs_MapDict + + type ('k,'v,'id) t type ('key, 'id ) dict = ('key, 'id) Bs_Dict.comparable @@ -176,5 +190,3 @@ val getData: ('a, 'b, 'c) t -> ('a, 'b, 'c) Bs_MapDict.t val packDictData: dict:('a, 'b) dict -> data:('a, 'c, 'b) Bs_MapDict.t -> ('a, 'c, 'b) t -module Int = Bs_MapInt -module String = Bs_MapString diff --git a/jscomp/others/bs_Set.ml b/jscomp/others/bs_Set.ml index 731f9b1e2a..7bd0ae308d 100644 --- a/jscomp/others/bs_Set.ml +++ b/jscomp/others/bs_Set.ml @@ -22,7 +22,10 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -module N = Bs_SetDict +module Int = Bs_SetInt +module String = Bs_SetString +module Dict = Bs_SetDict + module A = Bs_Array @@ -32,7 +35,7 @@ type ('key, 'id ) cmp = ('key, 'id) Bs_Dict.cmp module S = struct type ('k,'id) t = { cmp: ('k, 'id) cmp; - data: ('k, 'id) N.t; + data: ('k, 'id) Dict.t; } [@@bs.deriving abstract] end @@ -41,104 +44,104 @@ type ('k, 'id) t = ('k, 'id) S.t let ofArray (type elt) (type id) data ~(dict : (elt,id) dict) = let module M = (val dict ) in let cmp = M.cmp in - S.t ~cmp ~data:(N.ofArray ~cmp data) + S.t ~cmp ~data:(Dict.ofArray ~cmp data) let remove m e = let cmp, data = S.cmp m, S.data m in - let newData = N.remove ~cmp data e in + let newData = Dict.remove ~cmp data e in if newData == data then m else S.t ~cmp ~data:newData let add m e = let cmp, data = S.cmp m, S.data m in - let newData = N.add ~cmp data e in + let newData = Dict.add ~cmp data e in if newData == data then m else S.t ~cmp ~data:newData let mergeMany m e = let cmp = S.cmp m in - S.t ~cmp ~data:(N.mergeMany ~cmp (S.data m) e ) + S.t ~cmp ~data:(Dict.mergeMany ~cmp (S.data m) e ) let removeMany m e = let cmp = S.cmp m in - S.t ~cmp ~data:(N.removeMany ~cmp (S.data m) e) + S.t ~cmp ~data:(Dict.removeMany ~cmp (S.data m) e) let union m n = let cmp = S.cmp m in - S.t ~data:(N.union ~cmp (S.data m) (S.data n)) ~cmp + S.t ~data:(Dict.union ~cmp (S.data m) (S.data n)) ~cmp let intersect m n = let cmp = S.cmp m in - S.t ~data:(N.intersect ~cmp (S.data m) (S.data n)) ~cmp + S.t ~data:(Dict.intersect ~cmp (S.data m) (S.data n)) ~cmp let diff m n = let cmp = S.cmp m in - S.t ~cmp ~data:(N.diff ~cmp (S.data m) (S.data n)) + S.t ~cmp ~data:(Dict.diff ~cmp (S.data m) (S.data n)) let subset m n = let cmp = S.cmp m in - N.subset ~cmp (S.data m) (S.data n) + Dict.subset ~cmp (S.data m) (S.data n) let split m e = let cmp = S.cmp m in - let (l, r), b = N.split ~cmp (S.data m) e in + let (l, r), b = Dict.split ~cmp (S.data m) e in (S.t ~cmp ~data:l, S.t ~cmp ~data:r), b let make (type elt) (type id) ~(dict : (elt, id) dict) = let module M = (val dict) in - S.t ~cmp:M.cmp ~data:N.empty + S.t ~cmp:M.cmp ~data:Dict.empty -let isEmpty m = N.isEmpty (S.data m) +let isEmpty m = Dict.isEmpty (S.data m) let cmp m n = let cmp = S.cmp m in - N.cmp ~cmp (S.data m) (S.data n) + Dict.cmp ~cmp (S.data m) (S.data n) let eq m n = - N.eq ~cmp:(S.cmp m) (S.data m) (S.data n) + Dict.eq ~cmp:(S.cmp m) (S.data m) (S.data n) -let forEach m f = N.forEach (S.data m) f +let forEach m f = Dict.forEach (S.data m) f -let reduce m acc f = N.reduce (S.data m) acc f +let reduce m acc f = Dict.reduce (S.data m) acc f -let every m f = N.every (S.data m) f +let every m f = Dict.every (S.data m) f -let some m f = N.some (S.data m) f +let some m f = Dict.some (S.data m) f let keep m f = - S.t ~cmp:(S.cmp m) ~data:(N.keep (S.data m) f ) + S.t ~cmp:(S.cmp m) ~data:(Dict.keep (S.data m) f ) let partition m f = - let l,r = N.partition (S.data m) f in + let l,r = Dict.partition (S.data m) f in let cmp = S.cmp m in S.t ~data:l ~cmp, S.t ~data:r ~cmp -let size m = N.size (S.data m) -let toList m = N.toList (S.data m) -let toArray m = N.toArray (S.data m) +let size m = Dict.size (S.data m) +let toList m = Dict.toList (S.data m) +let toArray m = Dict.toArray (S.data m) -let minimum m = N.minimum (S.data m) -let minUndefined m = N.minUndefined (S.data m) -let maximum m = N.maximum (S.data m) -let maxUndefined m = N.maxUndefined (S.data m) +let minimum m = Dict.minimum (S.data m) +let minUndefined m = Dict.minUndefined (S.data m) +let maximum m = Dict.maximum (S.data m) +let maxUndefined m = Dict.maxUndefined (S.data m) let get m e = - N.get ~cmp:(S.cmp m) (S.data m) e + Dict.get ~cmp:(S.cmp m) (S.data m) e let getUndefined m e = - N.getUndefined ~cmp:(S.cmp m) (S.data m) e + Dict.getUndefined ~cmp:(S.cmp m) (S.data m) e let getExn m e = - N.getExn ~cmp:(S.cmp m) (S.data m) e + Dict.getExn ~cmp:(S.cmp m) (S.data m) e let has m e = - N.has ~cmp:(S.cmp m) (S.data m) e + Dict.has ~cmp:(S.cmp m) (S.data m) e let ofSortedArrayUnsafe (type elt) (type id) xs ~(dict : (elt,id) dict ) = let module M = (val dict) in - S.t ~cmp:M.cmp ~data:(N.ofSortedArrayUnsafe xs) + S.t ~cmp:M.cmp ~data:(Dict.ofSortedArrayUnsafe xs) @@ -157,8 +160,6 @@ let packDictData (type elt) (type id) ~(dict : (elt, id) dict) ~data = let module M = (val dict) in S.t ~cmp:M.cmp ~data -let checkInvariantInternal d = N.checkInvariantInternal (S.data d) +let checkInvariantInternal d = Dict.checkInvariantInternal (S.data d) -module Int = Bs_SetInt -module String = Bs_SetString diff --git a/jscomp/others/bs_Set.mli b/jscomp/others/bs_Set.mli index 6914a87492..b9ca9ecef2 100644 --- a/jscomp/others/bs_Set.mli +++ b/jscomp/others/bs_Set.mli @@ -22,8 +22,19 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) +(** specalized when key type is [int], more efficient + than the gerneic type +*) +module Int = Bs_SetInt +(** specalized when key type is [string], more efficient + than the gerneic type *) +module String = Bs_SetString +(** seprate function from data, a more verbsoe but slightly + more efficient +*) +module Dict = Bs_SetDict type ('k,'id) t @@ -112,5 +123,3 @@ val getData: ('k,'id) t -> ('k,'id) Bs_SetDict.t val getDict: ('k,'id) t -> ('k,'id) dict val packDictData: dict:('k, 'id) dict -> data:('k, 'id) Bs_SetDict.t -> ('k, 'id) t -module Int = Bs_SetInt -module String = Bs_SetString diff --git a/jscomp/others/bs_SetM.ml b/jscomp/others/bs_SetM.ml index a948be96e9..3631cf0c76 100644 --- a/jscomp/others/bs_SetM.ml +++ b/jscomp/others/bs_SetM.ml @@ -23,6 +23,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) +module Int = Bs_SetIntM +module String = Bs_SetStringM module N = Bs_internalAVLset module A = Bs_Array @@ -367,5 +369,3 @@ let has d x = let copy d = S.t ~data:(N.copy (S.data d)) ~cmp:(S.cmp d) -module Int = Bs_SetIntM -module String = Bs_SetStringM diff --git a/jscomp/others/bs_SetM.mli b/jscomp/others/bs_SetM.mli index 8fdae8b339..cd6c125773 100644 --- a/jscomp/others/bs_SetM.mli +++ b/jscomp/others/bs_SetM.mli @@ -23,6 +23,15 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) +(** specalized when key type is [int], more efficient + than the gerneic type +*) +module Int = Bs_SetIntM + +(** specalized when key type is [string], more efficient + than the gerneic type *) +module String = Bs_SetStringM + type ('k,'id) t type ('k, 'id) dict = ('k, 'id) Bs_Dict.comparable @@ -119,5 +128,3 @@ val checkInvariantInternal: _ t -> bool ('elt, 'id) t0] 2. It is not really significantly more *) -module Int = Bs_SetIntM -module String = Bs_SetStringM diff --git a/jscomp/others/bs_SortArray.ml b/jscomp/others/bs_SortArray.ml index 22c0f7f689..a461474129 100644 --- a/jscomp/others/bs_SortArray.ml +++ b/jscomp/others/bs_SortArray.ml @@ -23,6 +23,11 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) + +module Int = Bs_SortArrayInt + +module String = Bs_SortArrayString + module A = Bs_Array let rec sortedLengthAuxMore xs prec acc len lt = @@ -293,5 +298,3 @@ let binarySearchBy sorted key cmp : int = if c2 > 0 then - (len + 1) else binarySearchAux sorted 0 (len - 1) key cmp -module Int = Bs_SortArrayInt -module String = Bs_SortArrayString diff --git a/jscomp/others/bs_SortArray.mli b/jscomp/others/bs_SortArray.mli index 4fec34378f..9742145ea1 100644 --- a/jscomp/others/bs_SortArray.mli +++ b/jscomp/others/bs_SortArray.mli @@ -23,7 +23,14 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) +(** specalized when key type is [int], more efficient + than the gerneic type +*) +module Int = Bs_SortArrayInt +(** specalized when key type is [string], more efficient + than the gerneic type *) +module String = Bs_SortArrayString val strictlySortedLength: @@ -96,5 +103,3 @@ val binarySearchBy: *) -module Int = Bs_SortArrayInt -module String = Bs_SortArrayString diff --git a/jscomp/test/bs_MapInt_test.js b/jscomp/test/bs_MapInt_test.js index ccbacd62b3..7f53b81313 100644 --- a/jscomp/test/bs_MapInt_test.js +++ b/jscomp/test/bs_MapInt_test.js @@ -21,11 +21,14 @@ function test() { for(var i$2 = 0; i$2 <= 999999; ++i$2){ m = Bs_MapInt.remove(m, i$2); } - return should(+(Bs_MapInt.size(m) === 0)); + return should(Bs_MapInt.isEmpty(m)); } test(/* () */0); +var M = 0; + exports.should = should; +exports.M = M; exports.test = test; /* Not a pure module */ diff --git a/jscomp/test/bs_MapInt_test.ml b/jscomp/test/bs_MapInt_test.ml index e40d11e34e..93c09273b6 100644 --- a/jscomp/test/bs_MapInt_test.ml +++ b/jscomp/test/bs_MapInt_test.ml @@ -1,18 +1,20 @@ let should b = if not b then Js.Exn.raiseError "IMPOSSIBLE" + +module M = Bs.Map.Int let test () = - let m = ref Bs.MapInt.empty in + let m = ref M.empty in let count = 100_0000 - 1 in for i = 0 to count do - m := Bs.MapInt.set !m i i + m := M.set !m i i done; for i = 0 to count do - should (Bs.MapInt.get !m i <> None) + should (M.get !m i <> None) done; for i = 0 to count do - m := Bs.MapInt.remove !m i ; + m := M.remove !m i ; done ; - should (Bs.MapInt.size !m = 0) + should (M.isEmpty !m) let () = test () diff --git a/jscomp/test/bs_hashmap_test.ml b/jscomp/test/bs_hashmap_test.ml index e8c9643c57..5a8aaadfc8 100644 --- a/jscomp/test/bs_hashmap_test.ml +++ b/jscomp/test/bs_hashmap_test.ml @@ -2,7 +2,7 @@ let suites : Mt.pair_suites ref = ref [] let test_id = ref 0 let eqx loc x y = Mt.eq_suites ~test_id ~suites loc x y let b loc x = Mt.bool_suites ~test_id ~suites loc x -module N = Bs.UnorderedMutableMap +module N = Bs.HashMap module S = Bs.Map.Int (* module Y = struct type t = int diff --git a/jscomp/test/bs_hashset_int_test.ml b/jscomp/test/bs_hashset_int_test.ml index 6f13b227a3..f37f8a2b78 100644 --- a/jscomp/test/bs_hashset_int_test.ml +++ b/jscomp/test/bs_hashset_int_test.ml @@ -2,8 +2,8 @@ let suites : Mt.pair_suites ref = ref [] let test_id = ref 0 let eq loc x y = Mt.eq_suites ~test_id ~suites loc x y let b loc x = Mt.bool_suites ~test_id ~suites loc x -module N = Bs.UnorderedMutableSet.Int -module S = Bs.SetInt +module N = Bs.HashSet.Int +module S = Bs.Set.Int module I = Array_data_util let (++) = Bs.Array.concat diff --git a/jscomp/test/bs_hashtbl_string_test.ml b/jscomp/test/bs_hashtbl_string_test.ml index 4276f058d8..c27063ebf7 100644 --- a/jscomp/test/bs_hashtbl_string_test.ml +++ b/jscomp/test/bs_hashtbl_string_test.ml @@ -35,7 +35,7 @@ module Int = (val Bs.Dict.hashable ~eq:(fun[@bs] (x:int) y -> x = y ) ~hash:(fun [@bs] x -> Hashtbl.hash x)) -module N = Bs.UnorderedMutableMap +module N = Bs.HashMap let empty = N.make ~dict:(module Int) 500_000 @@ -60,7 +60,7 @@ let initial_size = 1_000_000 #.add (string_of_int i) i #.add (string_of_int i) i *) -module M = Bs.UnorderedMutableMap +module M = Bs.HashMap let bench2 (type t) (m : (string,t) Bs.Dict.hashable) = let empty = M.make ~dict:m initial_size in @@ -83,7 +83,7 @@ let bench2 (type t) (m : (string,t) Bs.Dict.hashable) = (* Bs.HashMap.logStats empty *) module Md = Bs.Map -module Md0 = Bs.MapDict +module Md0 = Bs.Map.Dict let bench3 (type t) (m : (string,t) Bs.Dict.comparable) = let empty = Md.make m in @@ -105,7 +105,7 @@ let bench3 (type t) (m : (string,t) Bs.Dict.comparable) = assert (Md0.size !table = 0) module Sx = (val Bs.Dict.comparable ~cmp:(fun [@bs] (x : string) y -> compare x y )) -module H = Bs.UnorderedMutableMap.String +module H = Bs.HashMap.String let bench4 () = let table = H.make initial_size in @@ -123,7 +123,7 @@ let bench4 () = done ; assert (H.isEmpty table) -module H0 = Bs.UnorderedMutableMap +module H0 = Bs.HashMap let bench5 () = let table = H0.make ~dict:(module Int) initial_size in @@ -143,7 +143,7 @@ let bench5 () = done ]; assert (H0.isEmpty table) -module HI = Bs.UnorderedMutableMap.Int +module HI = Bs.HashMap.Int let bench6 () = let table = HI.make initial_size in @@ -161,7 +161,7 @@ let bench6 () = done ; assert (HI.size table = 0) -module S = Bs.UnorderedMutableSetInt +module S = Bs.HashSet.Int let bench7 () = let table = (* [%time *) diff --git a/jscomp/test/bs_map_set_dict_test.ml b/jscomp/test/bs_map_set_dict_test.ml index 667fe84200..7206e0dbc7 100644 --- a/jscomp/test/bs_map_set_dict_test.ml +++ b/jscomp/test/bs_map_set_dict_test.ml @@ -14,7 +14,7 @@ module Icmp2 = compare x y )) module M = Bs.Map -module MI = Bs.MapInt +module MI = Bs.Map.Int (* module B = Bs.Bag *) module I = Array_data_util module A = Bs_Array @@ -30,7 +30,7 @@ let m = M.make (module Icmp2) let m2 : (int, string, _) M.t = M.make (module I2) let vv = MI.empty let vv2 = MI.empty -module Md0 = Bs.MapDict +module Md0 = Bs.Map.Dict let () = let count = 1_000_00 in let data = ref (M.getData m) in @@ -55,7 +55,7 @@ let () = let _m20 = M.make (module Icmp) in Js.log m11 -module S0 = Bs.SetDict +module S0 = Bs.Set.Dict let () = let count = 100_000 in let v = ISet.make (module Icmp2) in diff --git a/jscomp/test/bs_set_bench.ml b/jscomp/test/bs_set_bench.ml index 9b22b3c25b..271885750d 100644 --- a/jscomp/test/bs_set_bench.ml +++ b/jscomp/test/bs_set_bench.ml @@ -1,7 +1,7 @@ let count = 1_000_000 -module N = Bs.SetInt +module N = Bs.Set.Int let bench () = let data = ref N.empty in [%time for i = 0 to count do diff --git a/jscomp/test/bs_set_int_test.ml b/jscomp/test/bs_set_int_test.ml index 99b1b92687..bb3310961b 100644 --- a/jscomp/test/bs_set_int_test.ml +++ b/jscomp/test/bs_set_int_test.ml @@ -4,7 +4,7 @@ let eq loc x y = Mt.eq_suites ~suites ~test_id loc x y let b loc v = Mt.bool_suites ~suites ~test_id loc v -module N = Bs.SetInt +module N = Bs.Set.Int module I = Array_data_util module A = Bs_Array let (=~) s i = diff --git a/jscomp/test/imm_map_bench.ml b/jscomp/test/imm_map_bench.ml index 84e8c0ef98..bf5a46c0e6 100644 --- a/jscomp/test/imm_map_bench.ml +++ b/jscomp/test/imm_map_bench.ml @@ -31,7 +31,7 @@ let test () = should (mem v j) done -module M = Bs.MapInt +module M = Bs.Map.Int let test2 () = diff --git a/lib/js/bs.js b/lib/js/bs.js index ddbc91ab1e..d69aa54a28 100644 --- a/lib/js/bs.js +++ b/lib/js/bs.js @@ -15,50 +15,18 @@ var Range = 0; var $$Set = 0; -var SetDict = 0; - -var SetInt = 0; - -var SetString = 0; - -var MutableSet = 0; - -var MutableSetInt = 0; - -var MutableSetString = 0; - -var UnorderedMutableSet = 0; - -var UnorderedMutableSetInt = 0; - -var UnorderedMutableSetString = 0; - var $$Map = 0; -var MapDict = 0; - -var MapInt = 0; - -var MapString = 0; +var MutableSet = 0; var MutableMap = 0; -var MutableMapInt = 0; - -var MutableMapString = 0; - -var UnorderedMutableMap = 0; +var HashSet = 0; -var UnorderedMutableMapInt = 0; - -var UnorderedMutableMapString = 0; +var HashMap = 0; var SortArray = 0; -var SortArrayInt = 0; - -var SortArrayString = 0; - exports.Dict = Dict; exports.$$Array = $$Array; exports.MutableQueue = MutableQueue; @@ -66,26 +34,10 @@ exports.List = List; exports.MutableStack = MutableStack; exports.Range = Range; exports.$$Set = $$Set; -exports.SetDict = SetDict; -exports.SetInt = SetInt; -exports.SetString = SetString; -exports.MutableSet = MutableSet; -exports.MutableSetInt = MutableSetInt; -exports.MutableSetString = MutableSetString; -exports.UnorderedMutableSet = UnorderedMutableSet; -exports.UnorderedMutableSetInt = UnorderedMutableSetInt; -exports.UnorderedMutableSetString = UnorderedMutableSetString; exports.$$Map = $$Map; -exports.MapDict = MapDict; -exports.MapInt = MapInt; -exports.MapString = MapString; +exports.MutableSet = MutableSet; exports.MutableMap = MutableMap; -exports.MutableMapInt = MutableMapInt; -exports.MutableMapString = MutableMapString; -exports.UnorderedMutableMap = UnorderedMutableMap; -exports.UnorderedMutableMapInt = UnorderedMutableMapInt; -exports.UnorderedMutableMapString = UnorderedMutableMapString; +exports.HashSet = HashSet; +exports.HashMap = HashMap; exports.SortArray = SortArray; -exports.SortArrayInt = SortArrayInt; -exports.SortArrayString = SortArrayString; /* No side effect */ diff --git a/lib/js/bs_HashSet.js b/lib/js/bs_HashSet.js index e6521c8639..f9bae5491a 100644 --- a/lib/js/bs_HashSet.js +++ b/lib/js/bs_HashSet.js @@ -194,6 +194,10 @@ function mergeMany(h, arr) { return /* () */0; } +var Int = 0; + +var $$String = 0; + var clear = Bs_internalBucketsType.clear; var isEmpty = Bs_internalBucketsType.isEmpty; @@ -210,10 +214,8 @@ var toArray = Bs_internalSetBuckets.toArray; var getBucketHistogram = Bs_internalSetBuckets.getBucketHistogram; -var Int = 0; - -var $$String = 0; - +exports.Int = Int; +exports.$$String = $$String; exports.make = make; exports.clear = clear; exports.isEmpty = isEmpty; @@ -229,6 +231,4 @@ exports.toArray = toArray; exports.ofArray = ofArray; exports.mergeMany = mergeMany; exports.getBucketHistogram = getBucketHistogram; -exports.Int = Int; -exports.$$String = $$String; /* No side effect */ diff --git a/lib/js/bs_Map.js b/lib/js/bs_Map.js index de37537055..cacd4521d8 100644 --- a/lib/js/bs_Map.js +++ b/lib/js/bs_Map.js @@ -252,6 +252,11 @@ var Int = 0; var $$String = 0; +var Dict = 0; + +exports.Int = Int; +exports.$$String = $$String; +exports.Dict = Dict; exports.make = make; exports.isEmpty = isEmpty; exports.has = has; @@ -294,6 +299,4 @@ exports.mapWithKey = mapWithKey; exports.getDict = getDict; exports.getData = getData; exports.packDictData = packDictData; -exports.Int = Int; -exports.$$String = $$String; /* No side effect */ diff --git a/lib/js/bs_Set.js b/lib/js/bs_Set.js index 000133a6eb..0ae1325dcc 100644 --- a/lib/js/bs_Set.js +++ b/lib/js/bs_Set.js @@ -235,6 +235,11 @@ var Int = 0; var $$String = 0; +var Dict = 0; + +exports.Int = Int; +exports.$$String = $$String; +exports.Dict = Dict; exports.make = make; exports.ofArray = ofArray; exports.ofSortedArrayUnsafe = ofSortedArrayUnsafe; @@ -271,6 +276,4 @@ exports.checkInvariantInternal = checkInvariantInternal; exports.getData = getData; exports.getDict = getDict; exports.packDictData = packDictData; -exports.Int = Int; -exports.$$String = $$String; /* No side effect */ diff --git a/lib/js/bs_SetM.js b/lib/js/bs_SetM.js index 4a1f47cd85..efad417d82 100644 --- a/lib/js/bs_SetM.js +++ b/lib/js/bs_SetM.js @@ -485,6 +485,8 @@ var Int = 0; var $$String = 0; +exports.Int = Int; +exports.$$String = $$String; exports.make = make; exports.ofArray = ofArray; exports.ofSortedArrayUnsafe = ofSortedArrayUnsafe; @@ -521,6 +523,4 @@ exports.getUndefined = getUndefined; exports.getExn = getExn; exports.split = split; exports.checkInvariantInternal = checkInvariantInternal; -exports.Int = Int; -exports.$$String = $$String; /* No side effect */ diff --git a/lib/js/bs_SortArray.js b/lib/js/bs_SortArray.js index 020a44188a..fb08cecdf0 100644 --- a/lib/js/bs_SortArray.js +++ b/lib/js/bs_SortArray.js @@ -415,6 +415,8 @@ var Int = 0; var $$String = 0; +exports.Int = Int; +exports.$$String = $$String; exports.strictlySortedLength = strictlySortedLength; exports.isSorted = isSorted; exports.stableSortInPlaceBy = stableSortInPlaceBy; @@ -423,6 +425,4 @@ exports.union = union; exports.intersect = intersect; exports.diff = diff; exports.binarySearchBy = binarySearchBy; -exports.Int = Int; -exports.$$String = $$String; /* No side effect */ From 40b04566cca1a410b3d353c092bab0a3f6bf827f Mon Sep 17 00:00:00 2001 From: Hongbo Zhang Date: Thu, 1 Feb 2018 14:05:30 +0800 Subject: [PATCH 6/6] finalize toplevel structure --- jscomp/others/.depend | 39 +- jscomp/others/Makefile | 35 +- jscomp/others/bs.ml | 4 +- .../others/{bs_MapM.ml => bs_MutableMap.ml} | 5 +- .../others/{bs_MapM.mli => bs_MutableMap.mli} | 7 +- .../{bs_MapIntM.ml => bs_MutableMapInt.ml} | 0 .../{bs_MapIntM.mli => bs_MutableMapInt.mli} | 0 ...s_MapStringM.ml => bs_MutableMapString.ml} | 0 ...MapStringM.mli => bs_MutableMapString.mli} | 0 .../others/{bs_SetM.ml => bs_MutableSet.ml} | 4 +- .../others/{bs_SetM.mli => bs_MutableSet.mli} | 4 +- .../{bs_SetIntM.ml => bs_MutableSetInt.ml} | 0 ...s_SetStringM.ml => bs_MutableSetString.ml} | 0 ...SetStringM.mli => bs_MutableSetString.mli} | 0 jscomp/others/bs_SetIntM.mli | 101 ---- jscomp/test/bs_mutable_set_test.js | 176 +++--- jscomp/test/bs_poly_mutable_map_test.js | 14 +- jscomp/test/bs_poly_mutable_set_test.js | 112 ++-- lib/js/bs_MutableMap.js | 364 ++++++++++++ lib/js/bs_MutableMapInt.js | 333 +++++++++++ lib/js/bs_MutableMapString.js | 333 +++++++++++ lib/js/bs_MutableSet.js | 526 ++++++++++++++++++ lib/js/bs_MutableSetInt.js | 502 +++++++++++++++++ lib/js/bs_MutableSetString.js | 485 ++++++++++++++++ 24 files changed, 2742 insertions(+), 302 deletions(-) rename jscomp/others/{bs_MapM.ml => bs_MutableMap.ml} (99%) rename jscomp/others/{bs_MapM.mli => bs_MutableMap.mli} (98%) rename jscomp/others/{bs_MapIntM.ml => bs_MutableMapInt.ml} (100%) rename jscomp/others/{bs_MapIntM.mli => bs_MutableMapInt.mli} (100%) rename jscomp/others/{bs_MapStringM.ml => bs_MutableMapString.ml} (100%) rename jscomp/others/{bs_MapStringM.mli => bs_MutableMapString.mli} (100%) rename jscomp/others/{bs_SetM.ml => bs_MutableSet.ml} (99%) rename jscomp/others/{bs_SetM.mli => bs_MutableSet.mli} (98%) rename jscomp/others/{bs_SetIntM.ml => bs_MutableSetInt.ml} (100%) rename jscomp/others/{bs_SetStringM.ml => bs_MutableSetString.ml} (100%) rename jscomp/others/{bs_SetStringM.mli => bs_MutableSetString.mli} (100%) delete mode 100644 jscomp/others/bs_SetIntM.mli create mode 100644 lib/js/bs_MutableMap.js create mode 100644 lib/js/bs_MutableMapInt.js create mode 100644 lib/js/bs_MutableMapString.js create mode 100644 lib/js/bs_MutableSet.js create mode 100644 lib/js/bs_MutableSetInt.js create mode 100644 lib/js/bs_MutableSetString.js diff --git a/jscomp/others/.depend b/jscomp/others/.depend index 7a3b955f1c..53cec4de0b 100644 --- a/jscomp/others/.depend +++ b/jscomp/others/.depend @@ -21,8 +21,6 @@ bs_internalAVLset.cmj : bs_SortArray.cmj bs_Dict.cmj bs_Array.cmj \ bs_internalAVLset.cmi bs_internalAVLtree.cmj : bs_SortArray.cmj bs_Dict.cmj bs_Array.cmj \ bs_internalAVLtree.cmi -bs_SetIntM.cmj : bs_internalSetInt.cmj bs_internalAVLset.cmj \ - bs_SortArrayInt.cmj bs_Array.cmj bs_SetIntM.cmi bs_Queue.cmj : bs_Array.cmj bs_Queue.cmi bs_List.cmj : bs_Array.cmj bs_List.cmi bs_SortArray.cmj : bs_SortArrayString.cmj bs_SortArrayInt.cmj bs_Array.cmj \ @@ -59,28 +57,29 @@ bs_MapString.cmj : bs_internalMapString.cmj bs_internalAVLtree.cmj \ bs_Array.cmj bs_MapString.cmi bs_MapInt.cmj : bs_internalMapInt.cmj bs_internalAVLtree.cmj bs_Array.cmj \ bs_MapInt.cmi -bs_MapStringM.cmj : bs_internalMapString.cmj bs_internalAVLtree.cmj \ - bs_Array.cmj bs_MapStringM.cmi -bs_MapIntM.cmj : bs_internalMapInt.cmj bs_internalAVLtree.cmj bs_Array.cmj \ - bs_MapIntM.cmi bs_Set.cmj : bs_SetString.cmj bs_SetInt.cmj bs_SetDict.cmj bs_Dict.cmj \ bs_Array.cmj bs_Set.cmi -bs_SetM.cmj : bs_internalAVLset.cmj bs_SortArray.cmj bs_SetStringM.cmj \ - bs_SetIntM.cmj bs_Dict.cmj bs_Array.cmj bs_SetM.cmi -bs_MapM.cmj : bs_internalAVLtree.cmj bs_MapStringM.cmj bs_MapIntM.cmj \ - bs_Dict.cmj bs_Array.cmj bs_MapM.cmi +bs_MutableSet.cmj : bs_internalAVLset.cmj bs_SortArray.cmj \ + bs_MutableSetString.cmj bs_MutableSetInt.cmj bs_Dict.cmj bs_Array.cmj \ + bs_MutableSet.cmi +bs_MutableSetInt.cmj : bs_internalSetInt.cmj bs_internalAVLset.cmj \ + bs_SortArrayInt.cmj bs_Array.cmj +bs_MutableSetString.cmj : bs_internalSetString.cmj bs_internalAVLset.cmj \ + bs_SortArrayString.cmj bs_Array.cmj bs_MutableSetString.cmi +bs_MutableMap.cmj : bs_internalAVLtree.cmj bs_MutableMapString.cmj \ + bs_MutableMapInt.cmj bs_Dict.cmj bs_Array.cmj bs_MutableMap.cmi +bs_MutableMapInt.cmj : bs_internalMapInt.cmj bs_internalAVLtree.cmj \ + bs_Array.cmj bs_MutableMapInt.cmi +bs_MutableMapString.cmj : bs_internalMapString.cmj bs_internalAVLtree.cmj \ + bs_Array.cmj bs_MutableMapString.cmi bs_internalSetInt.cmj : bs_internalAVLset.cmj bs_SortArrayInt.cmj \ bs_Array.cmj bs_internalSetString.cmj : bs_internalAVLset.cmj bs_SortArrayString.cmj \ bs_Array.cmj bs_SetInt.cmj : bs_internalSetInt.cmj bs_internalAVLset.cmj bs_Array.cmj \ bs_SetInt.cmi -bs_SetIntM.cmj : bs_internalSetInt.cmj bs_internalAVLset.cmj \ - bs_SortArrayInt.cmj bs_Array.cmj bs_SetIntM.cmi bs_SetString.cmj : bs_internalSetString.cmj bs_internalAVLset.cmj \ bs_Array.cmj bs_SetString.cmi -bs_SetStringM.cmj : bs_internalSetString.cmj bs_internalAVLset.cmj \ - bs_SortArrayString.cmj bs_Array.cmj bs_SetStringM.cmi bs_Stack.cmj : bs_Stack.cmi node_child_process.cmj : node.cmj js_boolean.cmj : js_boolean.cmi @@ -107,7 +106,6 @@ js_mapperRt.cmi : bs_Array.cmi : bs_internalAVLset.cmi : bs_Dict.cmi bs_internalAVLtree.cmi : bs_Dict.cmi -bs_SetIntM.cmi : bs_Queue.cmi : bs_List.cmi : bs_SortArray.cmi : bs_SortArrayString.cmi bs_SortArrayInt.cmi @@ -127,15 +125,14 @@ bs_SetDict.cmi : bs_Dict.cmi bs_Map.cmi : bs_MapString.cmi bs_MapInt.cmi bs_MapDict.cmi bs_Dict.cmi bs_MapString.cmi : bs_MapInt.cmi : -bs_MapStringM.cmi : -bs_MapIntM.cmi : bs_Set.cmi : bs_SetString.cmi bs_SetInt.cmi bs_SetDict.cmi bs_Dict.cmi -bs_SetM.cmi : bs_SetStringM.cmi bs_SetIntM.cmi bs_Dict.cmi -bs_MapM.cmi : bs_MapStringM.cmi bs_MapIntM.cmi bs_Dict.cmi +bs_MutableSet.cmi : bs_MutableSetString.cmi bs_MutableSetInt.cmj bs_Dict.cmi +bs_MutableSetString.cmi : +bs_MutableMap.cmi : bs_MutableMapString.cmi bs_MutableMapInt.cmi bs_Dict.cmi +bs_MutableMapInt.cmi : +bs_MutableMapString.cmi : bs_SetInt.cmi : -bs_SetIntM.cmi : bs_SetString.cmi : -bs_SetStringM.cmi : bs_Stack.cmi : js_boolean.cmi : js_dict.cmi : diff --git a/jscomp/others/Makefile b/jscomp/others/Makefile index 76e0a91930..414020da5c 100644 --- a/jscomp/others/Makefile +++ b/jscomp/others/Makefile @@ -13,7 +13,6 @@ SOURCE_LIST= node_path node_fs node_process dict node_module js_array js_string bs_Array\ bs_internalAVLset\ bs_internalAVLtree\ - bs_SetIntM\ bs_internalMutableAVL\ bs_Queue\ bs_List\ @@ -36,18 +35,18 @@ SOURCE_LIST= node_path node_fs node_process dict node_module js_array js_string bs_internalMapString\ bs_MapString \ bs_MapInt\ - bs_MapStringM \ - bs_MapIntM\ bs_internalSet\ bs_Set\ - bs_SetM\ - bs_MapM\ + bs_MutableSet\ + bs_MutableSetInt\ + bs_MutableSetString\ + bs_MutableMap\ + bs_MutableMapInt\ + bs_MutableMapString\ bs_internalSetInt\ bs_internalSetString\ bs_SetInt\ - bs_SetIntM\ bs_SetString\ - bs_SetStringM\ bs_Stack\ node_child_process \ js_boolean js_math\ @@ -90,14 +89,14 @@ clean:: bs_MapInt.ml bs_MapInt.mli bs_MapString.ml bs_MapString.mli \ bs_internalSetInt.ml bs_internalSetString.ml \ bs_SetInt.ml bs_SetInt.mli bs_SetString.ml bs_SetString.mli \ - bs_SetIntM.ml bs_SetIntM.mli bs_SetStringM.ml bs_SetStringM.mli\ + bs_MutableSetInt.ml bs_MutableSetInt.mli bs_MutableSetString.ml bs_MutableSetString.mli\ bs_SortArrayInt.ml bs_SortArrayInt.mli bs_SortArrayString.ml bs_SortArrayString.mli\ bs_internalMapInt.ml bs_internalMapInt.mli \ bs_internalMapIntM.ml bs_internalMapIntM.mli \ bs_internalMapString.ml bs_internalMapString.mli\ bs_internalMapStringM.ml bs_internalMapStringM.mli\ - bs_MapStringM.mli bs_MapStringM.ml\ - bs_MapIntM.mli bs_MapIntM.ml + bs_MutableMapString.mli bs_MutableMapString.ml\ + bs_MutableMapInt.mli bs_MutableMapInt.ml ifndef BS_RELEASE_BUILD bs_HashSetString.ml: hashset.cppo.ml @@ -124,13 +123,13 @@ bs_MapString.mli: map.cppo.mli cppo -D TYPE_STRING $^ > $@ bs_MapInt.mli: map.cppo.mli cppo -D TYPE_INT $^ > $@ -bs_MapStringM.mli: mapm.cppo.mli +bs_MutableMapString.mli: mapm.cppo.mli cppo -D TYPE_STRING $^ > $@ -bs_MapIntM.mli: mapm.cppo.mli +bs_MutableMapInt.mli: mapm.cppo.mli cppo -D TYPE_INT $^ > $@ -bs_MapStringM.ml: mapm.cppo.ml +bs_MutableMapString.ml: mapm.cppo.ml cppo -D TYPE_STRING $^ > $@ -bs_MapIntM.ml: mapm.cppo.ml +bs_MutableMapInt.ml: mapm.cppo.ml cppo -D TYPE_INT $^ > $@ bs_internalMapInt.ml : internal_map.cppo.ml cppo -D TYPE_INT $^ > $@ @@ -151,13 +150,13 @@ bs_SetInt.mli: set.cppo.mli bs_SetString.mli: set.cppo.mli cppo -D TYPE_STRING $^ > $@ -bs_SetIntM.ml: setm.cppo.ml +bs_MutableSetInt.ml: setm.cppo.ml cppo -D TYPE_INT $^ > $@ -bs_SetStringM.ml: setm.cppo.ml +bs_MutableSetString.ml: setm.cppo.ml cppo -D TYPE_STRING $^ > $@ -bs_SetIntM.mli: setm.cppo.mli +bs_MutabgleSetInt.mli: setm.cppo.mli cppo -D TYPE_INT $^ > $@ -bs_SetStringM.mli: setm.cppo.mli +bs_MutableSetString.mli: setm.cppo.mli cppo -D TYPE_STRING $^ > $@ bs_SortArrayInt.ml : sort.cppo.ml diff --git a/jscomp/others/bs.ml b/jscomp/others/bs.ml index 4d3bcab0bb..5266281f8c 100644 --- a/jscomp/others/bs.ml +++ b/jscomp/others/bs.ml @@ -60,7 +60,7 @@ module Map = Bs_Map It also has two specialized inner modules {!Bs.MutableSet.Int} and {!Bs.MutableSet.String} *) -module MutableSet = Bs_SetM +module MutableSet = Bs_MutableSet (** {!Bs.MutableMap} The toplevel provides generic mutable map operations. @@ -68,7 +68,7 @@ module MutableSet = Bs_SetM {!Bs.MutableMap.Int} and {!Bs.MutableMap.String} *) -module MutableMap = Bs_MapM +module MutableMap = Bs_MutableMap (** {!Bs.HashSet} diff --git a/jscomp/others/bs_MapM.ml b/jscomp/others/bs_MutableMap.ml similarity index 99% rename from jscomp/others/bs_MapM.ml rename to jscomp/others/bs_MutableMap.ml index 089382d678..fbda90967e 100644 --- a/jscomp/others/bs_MapM.ml +++ b/jscomp/others/bs_MutableMap.ml @@ -23,6 +23,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) +module Int = Bs_MutableMapInt +module String = Bs_MutableMapString module N = Bs_internalAVLtree module A = Bs_Array @@ -237,6 +239,3 @@ let mergeMany d xs = S.dataSet d newRoot -module Int = Bs_MapIntM -module String = Bs_MapStringM - diff --git a/jscomp/others/bs_MapM.mli b/jscomp/others/bs_MutableMap.mli similarity index 98% rename from jscomp/others/bs_MapM.mli rename to jscomp/others/bs_MutableMap.mli index ab3ee4770c..93e686e062 100644 --- a/jscomp/others/bs_MapM.mli +++ b/jscomp/others/bs_MutableMap.mli @@ -23,6 +23,11 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) +module Int = Bs_MutableMapInt + +module String = Bs_MutableMapString + + type ('k,'v,'id) t type ('key, 'id) dict = ('key, 'id) Bs_Dict.comparable @@ -116,5 +121,3 @@ val mapWithKey: ('k, 'a, 'id) t -> ('k -> 'a -> 'b [@bs]) -> ('k, 'b, 'id) t -module Int = Bs_MapIntM -module String = Bs_MapStringM diff --git a/jscomp/others/bs_MapIntM.ml b/jscomp/others/bs_MutableMapInt.ml similarity index 100% rename from jscomp/others/bs_MapIntM.ml rename to jscomp/others/bs_MutableMapInt.ml diff --git a/jscomp/others/bs_MapIntM.mli b/jscomp/others/bs_MutableMapInt.mli similarity index 100% rename from jscomp/others/bs_MapIntM.mli rename to jscomp/others/bs_MutableMapInt.mli diff --git a/jscomp/others/bs_MapStringM.ml b/jscomp/others/bs_MutableMapString.ml similarity index 100% rename from jscomp/others/bs_MapStringM.ml rename to jscomp/others/bs_MutableMapString.ml diff --git a/jscomp/others/bs_MapStringM.mli b/jscomp/others/bs_MutableMapString.mli similarity index 100% rename from jscomp/others/bs_MapStringM.mli rename to jscomp/others/bs_MutableMapString.mli diff --git a/jscomp/others/bs_SetM.ml b/jscomp/others/bs_MutableSet.ml similarity index 99% rename from jscomp/others/bs_SetM.ml rename to jscomp/others/bs_MutableSet.ml index 3631cf0c76..8d2231d620 100644 --- a/jscomp/others/bs_SetM.ml +++ b/jscomp/others/bs_MutableSet.ml @@ -23,8 +23,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -module Int = Bs_SetIntM -module String = Bs_SetStringM +module Int = Bs_MutableSetInt +module String = Bs_MutableSetString module N = Bs_internalAVLset module A = Bs_Array diff --git a/jscomp/others/bs_SetM.mli b/jscomp/others/bs_MutableSet.mli similarity index 98% rename from jscomp/others/bs_SetM.mli rename to jscomp/others/bs_MutableSet.mli index cd6c125773..3b96f45ca5 100644 --- a/jscomp/others/bs_SetM.mli +++ b/jscomp/others/bs_MutableSet.mli @@ -26,11 +26,11 @@ (** specalized when key type is [int], more efficient than the gerneic type *) -module Int = Bs_SetIntM +module Int = Bs_MutableSetInt (** specalized when key type is [string], more efficient than the gerneic type *) -module String = Bs_SetStringM +module String = Bs_MutableSetString type ('k,'id) t diff --git a/jscomp/others/bs_SetIntM.ml b/jscomp/others/bs_MutableSetInt.ml similarity index 100% rename from jscomp/others/bs_SetIntM.ml rename to jscomp/others/bs_MutableSetInt.ml diff --git a/jscomp/others/bs_SetStringM.ml b/jscomp/others/bs_MutableSetString.ml similarity index 100% rename from jscomp/others/bs_SetStringM.ml rename to jscomp/others/bs_MutableSetString.ml diff --git a/jscomp/others/bs_SetStringM.mli b/jscomp/others/bs_MutableSetString.mli similarity index 100% rename from jscomp/others/bs_SetStringM.mli rename to jscomp/others/bs_MutableSetString.mli diff --git a/jscomp/others/bs_SetIntM.mli b/jscomp/others/bs_SetIntM.mli deleted file mode 100644 index 52a6105e33..0000000000 --- a/jscomp/others/bs_SetIntM.mli +++ /dev/null @@ -1,101 +0,0 @@ -# 1 "setm.cppo.mli" -(* 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. *) - -# 28 -type elt = int - -# 33 -type t -val make: unit -> t - -val ofArray: elt array -> t -val ofSortedArrayUnsafe: elt array -> t -val copy: t -> t -val isEmpty: t -> bool -val has: t -> elt -> bool - -val add: t -> elt -> unit -val addCheck: t -> elt -> bool -val mergeMany: t -> elt array -> unit -val remove: t -> elt -> unit -val removeCheck: t -> elt -> bool -val removeMany: t -> elt array -> unit - -val union: t -> t -> t -val intersect: t -> t -> t -val diff: t -> t -> t -val subset: t -> t -> bool - -val cmp: t -> t -> int -val eq: t -> t -> bool - - - -val forEach: t -> (elt -> unit [@bs]) -> unit -(** In increasing order*) - -val reduce: t -> 'a -> ('a -> elt -> 'a [@bs]) -> 'a -(** Iterate in increasing order. *) - -val every: t -> (elt -> bool [@bs]) -> bool -(** [every p s] checks if all elements of the set - satisfy the predicate [p]. Order unspecified. *) - -val some: t -> (elt -> bool [@bs]) -> bool -(** [some p s] checks if at least one element of - the set satisfies the predicate [p]. Oder unspecified. *) - -val keep: t -> (elt -> bool [@bs]) -> t -(** [keep s p] returns a fresh copy of the set of all elements in [s] - that satisfy predicate [p]. *) - -val partition: t -> (elt -> bool [@bs]) -> t * t -(** [partition s p] returns a fresh copy pair of sets [(s1, s2)], where - [s1] is the set of all the elements of [s] that satisfy the - predicate [p], and [s2] is the set of all the elements of - [s] that do not satisfy [p]. *) - -val size: t -> int -val toList: t -> elt list - (** In increasing order with respect *) -val toArray: t -> elt array - - -val minimum: t -> elt option -val minUndefined: t -> elt Js.undefined -val maximum: t -> elt option -val maxUndefined: t -> elt Js.undefined - -val get: t -> elt -> elt option -val getUndefined: t -> elt -> elt Js.undefined -val getExn: t -> elt -> elt -val split: t -> elt -> (t * t) * bool -(** - [split s key] return a fresh copy of each -*) - -val checkInvariantInternal: t -> bool - - diff --git a/jscomp/test/bs_mutable_set_test.js b/jscomp/test/bs_mutable_set_test.js index b27654e157..89811efc67 100644 --- a/jscomp/test/bs_mutable_set_test.js +++ b/jscomp/test/bs_mutable_set_test.js @@ -4,9 +4,9 @@ var Mt = require("./mt.js"); var Bs_List = require("../../lib/js/bs_List.js"); var Bs_Array = require("../../lib/js/bs_Array.js"); var Bs_Range = require("../../lib/js/bs_Range.js"); -var Bs_SetIntM = require("../../lib/js/bs_SetIntM.js"); var Caml_array = require("../../lib/js/caml_array.js"); var Array_data_util = require("./array_data_util.js"); +var Bs_MutableSetInt = require("../../lib/js/bs_MutableSetInt.js"); var Bs_internalAVLset = require("../../lib/js/bs_internalAVLset.js"); var Bs_internalSetInt = require("../../lib/js/bs_internalSetInt.js"); @@ -28,13 +28,13 @@ var u = { data: Bs_internalSetInt.ofArray(xs) }; -b("File \"bs_mutable_set_test.ml\", line 20, characters 4-11", Bs_SetIntM.removeCheck(u, 0)); +b("File \"bs_mutable_set_test.ml\", line 20, characters 4-11", Bs_MutableSetInt.removeCheck(u, 0)); -b("File \"bs_mutable_set_test.ml\", line 21, characters 4-11", 1 - Bs_SetIntM.removeCheck(u, 0)); +b("File \"bs_mutable_set_test.ml\", line 21, characters 4-11", 1 - Bs_MutableSetInt.removeCheck(u, 0)); -b("File \"bs_mutable_set_test.ml\", line 22, characters 4-11", Bs_SetIntM.removeCheck(u, 30)); +b("File \"bs_mutable_set_test.ml\", line 22, characters 4-11", Bs_MutableSetInt.removeCheck(u, 30)); -b("File \"bs_mutable_set_test.ml\", line 23, characters 4-11", Bs_SetIntM.removeCheck(u, 20)); +b("File \"bs_mutable_set_test.ml\", line 23, characters 4-11", Bs_MutableSetInt.removeCheck(u, 20)); eq("File \"bs_mutable_set_test.ml\", line 24, characters 5-12", Bs_internalAVLset.size(u.data), 28); @@ -44,61 +44,61 @@ b("File \"bs_mutable_set_test.ml\", line 26, characters 4-11", +(29 === Bs_inter b("File \"bs_mutable_set_test.ml\", line 27, characters 4-11", +(1 === Bs_internalAVLset.minUndefined(u.data))); -Bs_SetIntM.add(u, 3); +Bs_MutableSetInt.add(u, 3); for(var i = 0 ,i_finish = r.length - 1 | 0; i <= i_finish; ++i){ - Bs_SetIntM.remove(u, r[i]); + Bs_MutableSetInt.remove(u, r[i]); } b("File \"bs_mutable_set_test.ml\", line 32, characters 4-11", Bs_internalAVLset.isEmpty(u.data)); -Bs_SetIntM.add(u, 0); +Bs_MutableSetInt.add(u, 0); -Bs_SetIntM.add(u, 1); +Bs_MutableSetInt.add(u, 1); -Bs_SetIntM.add(u, 2); +Bs_MutableSetInt.add(u, 2); -Bs_SetIntM.add(u, 0); +Bs_MutableSetInt.add(u, 0); eq("File \"bs_mutable_set_test.ml\", line 37, characters 5-12", Bs_internalAVLset.size(u.data), 3); b("File \"bs_mutable_set_test.ml\", line 38, characters 4-11", 1 - Bs_internalAVLset.isEmpty(u.data)); for(var i$1 = 0; i$1 <= 3; ++i$1){ - Bs_SetIntM.remove(u, i$1); + Bs_MutableSetInt.remove(u, i$1); } b("File \"bs_mutable_set_test.ml\", line 42, characters 4-11", Bs_internalAVLset.isEmpty(u.data)); -Bs_SetIntM.mergeMany(u, Array_data_util.randomRange(0, 20000)); +Bs_MutableSetInt.mergeMany(u, Array_data_util.randomRange(0, 20000)); -Bs_SetIntM.mergeMany(u, Array_data_util.randomRange(0, 200)); +Bs_MutableSetInt.mergeMany(u, Array_data_util.randomRange(0, 200)); eq("File \"bs_mutable_set_test.ml\", line 45, characters 5-12", Bs_internalAVLset.size(u.data), 20001); -Bs_SetIntM.removeMany(u, Array_data_util.randomRange(0, 200)); +Bs_MutableSetInt.removeMany(u, Array_data_util.randomRange(0, 200)); eq("File \"bs_mutable_set_test.ml\", line 47, characters 5-12", Bs_internalAVLset.size(u.data), 19800); -Bs_SetIntM.removeMany(u, Array_data_util.randomRange(0, 1000)); +Bs_MutableSetInt.removeMany(u, Array_data_util.randomRange(0, 1000)); eq("File \"bs_mutable_set_test.ml\", line 49, characters 5-12", Bs_internalAVLset.size(u.data), 19000); -Bs_SetIntM.removeMany(u, Array_data_util.randomRange(0, 1000)); +Bs_MutableSetInt.removeMany(u, Array_data_util.randomRange(0, 1000)); eq("File \"bs_mutable_set_test.ml\", line 51, characters 5-12", Bs_internalAVLset.size(u.data), 19000); -Bs_SetIntM.removeMany(u, Array_data_util.randomRange(1000, 10000)); +Bs_MutableSetInt.removeMany(u, Array_data_util.randomRange(1000, 10000)); eq("File \"bs_mutable_set_test.ml\", line 53, characters 5-12", Bs_internalAVLset.size(u.data), 10000); -Bs_SetIntM.removeMany(u, Array_data_util.randomRange(10000, 19999)); +Bs_MutableSetInt.removeMany(u, Array_data_util.randomRange(10000, 19999)); eq("File \"bs_mutable_set_test.ml\", line 55, characters 5-12", Bs_internalAVLset.size(u.data), 1); b("File \"bs_mutable_set_test.ml\", line 56, characters 4-11", Bs_internalSetInt.has(u.data, 20000)); -Bs_SetIntM.removeMany(u, Array_data_util.randomRange(10000, 30000)); +Bs_MutableSetInt.removeMany(u, Array_data_util.randomRange(10000, 30000)); b("File \"bs_mutable_set_test.ml\", line 58, characters 4-11", Bs_internalAVLset.isEmpty(u.data)); @@ -109,7 +109,7 @@ var v = { }; var bs = Bs_Array.map(Array_data_util.randomRange(500, 1499), (function (x) { - return Bs_SetIntM.removeCheck(v, x); + return Bs_MutableSetInt.removeCheck(v, x); })); var indeedRemoved = Bs_Array.reduce(bs, 0, (function (acc, x) { @@ -125,7 +125,7 @@ eq("File \"bs_mutable_set_test.ml\", line 65, characters 5-12", indeedRemoved, 5 eq("File \"bs_mutable_set_test.ml\", line 66, characters 5-12", Bs_internalAVLset.size(v.data), 501); var cs = Bs_Array.map(Array_data_util.randomRange(500, 2000), (function (x) { - return Bs_SetIntM.addCheck(v, x); + return Bs_MutableSetInt.addCheck(v, x); })); var indeedAded = Bs_Array.reduce(cs, 0, (function (acc, x) { @@ -154,7 +154,7 @@ eq("File \"bs_mutable_set_test.ml\", line 74, characters 5-12", Bs_internalAVLse eq("File \"bs_mutable_set_test.ml\", line 75, characters 5-12", Bs_internalAVLset.maxUndefined(v.data), 2000); -eq("File \"bs_mutable_set_test.ml\", line 76, characters 5-12", Bs_SetIntM.reduce(v, 0, (function (x, y) { +eq("File \"bs_mutable_set_test.ml\", line 76, characters 5-12", Bs_MutableSetInt.reduce(v, 0, (function (x, y) { return x + y | 0; })), 1876250); @@ -172,7 +172,7 @@ eq("File \"bs_mutable_set_test.ml\", line 80, characters 5-12", Bs_internalSetIn eq("File \"bs_mutable_set_test.ml\", line 81, characters 5-12", Bs_internalSetInt.get(v.data, 1200), /* Some */[1200]); -var match = Bs_SetIntM.split(v, 1000); +var match = Bs_MutableSetInt.split(v, 1000); var match$1 = match[0]; @@ -190,19 +190,19 @@ b("File \"bs_mutable_set_test.ml\", line 85, characters 4-11", Bs_Array.eq(Bs_in return +(x === y); }))); -b("File \"bs_mutable_set_test.ml\", line 86, characters 5-12", Bs_SetIntM.subset(aa, v)); +b("File \"bs_mutable_set_test.ml\", line 86, characters 5-12", Bs_MutableSetInt.subset(aa, v)); -b("File \"bs_mutable_set_test.ml\", line 87, characters 4-11", Bs_SetIntM.subset(bb, v)); +b("File \"bs_mutable_set_test.ml\", line 87, characters 4-11", Bs_MutableSetInt.subset(bb, v)); -var d$1 = Bs_SetIntM.intersect(aa, bb); +var d$1 = Bs_MutableSetInt.intersect(aa, bb); b("File \"bs_mutable_set_test.ml\", line 88, characters 4-11", Bs_internalAVLset.isEmpty(d$1.data)); -var c = Bs_SetIntM.removeCheck(v, 1000); +var c = Bs_MutableSetInt.removeCheck(v, 1000); b("File \"bs_mutable_set_test.ml\", line 90, characters 4-11", c); -var match$2 = Bs_SetIntM.split(v, 1000); +var match$2 = Bs_MutableSetInt.split(v, 1000); var match$3 = match$2[0]; @@ -220,11 +220,11 @@ b("File \"bs_mutable_set_test.ml\", line 94, characters 4-11", Bs_Array.eq(Bs_in return +(x === y); }))); -b("File \"bs_mutable_set_test.ml\", line 95, characters 5-12", Bs_SetIntM.subset(aa$1, v)); +b("File \"bs_mutable_set_test.ml\", line 95, characters 5-12", Bs_MutableSetInt.subset(aa$1, v)); -b("File \"bs_mutable_set_test.ml\", line 96, characters 4-11", Bs_SetIntM.subset(bb$1, v)); +b("File \"bs_mutable_set_test.ml\", line 96, characters 4-11", Bs_MutableSetInt.subset(bb$1, v)); -var d$2 = Bs_SetIntM.intersect(aa$1, bb$1); +var d$2 = Bs_MutableSetInt.intersect(aa$1, bb$1); b("File \"bs_mutable_set_test.ml\", line 97, characters 4-11", Bs_internalAVLset.isEmpty(d$2.data)); @@ -240,11 +240,11 @@ var bb$2 = { data: Bs_internalSetInt.ofArray(xs$3) }; -var cc = Bs_SetIntM.union(aa$2, bb$2); +var cc = Bs_MutableSetInt.union(aa$2, bb$2); var xs$4 = Array_data_util.randomRange(0, 120); -b("File \"bs_mutable_set_test.ml\", line 106, characters 4-11", Bs_SetIntM.eq(cc, { +b("File \"bs_mutable_set_test.ml\", line 106, characters 4-11", Bs_MutableSetInt.eq(cc, { data: Bs_internalSetInt.ofArray(xs$4) })); @@ -254,7 +254,7 @@ var xs$6 = Array_data_util.randomRange(21, 40); var xs$7 = Array_data_util.randomRange(0, 40); -b("File \"bs_mutable_set_test.ml\", line 108, characters 4-11", Bs_SetIntM.eq(Bs_SetIntM.union({ +b("File \"bs_mutable_set_test.ml\", line 108, characters 4-11", Bs_MutableSetInt.eq(Bs_MutableSetInt.union({ data: Bs_internalSetInt.ofArray(xs$5) }, { data: Bs_internalSetInt.ofArray(xs$6) @@ -262,11 +262,11 @@ b("File \"bs_mutable_set_test.ml\", line 108, characters 4-11", Bs_SetIntM.eq(Bs data: Bs_internalSetInt.ofArray(xs$7) })); -var dd = Bs_SetIntM.intersect(aa$2, bb$2); +var dd = Bs_MutableSetInt.intersect(aa$2, bb$2); var xs$8 = Array_data_util.randomRange(40, 100); -b("File \"bs_mutable_set_test.ml\", line 113, characters 4-11", Bs_SetIntM.eq(dd, { +b("File \"bs_mutable_set_test.ml\", line 113, characters 4-11", Bs_MutableSetInt.eq(dd, { data: Bs_internalSetInt.ofArray(xs$8) })); @@ -274,7 +274,7 @@ var xs$9 = Array_data_util.randomRange(0, 20); var xs$10 = Array_data_util.randomRange(21, 40); -b("File \"bs_mutable_set_test.ml\", line 114, characters 4-11", Bs_SetIntM.eq(Bs_SetIntM.intersect({ +b("File \"bs_mutable_set_test.ml\", line 114, characters 4-11", Bs_MutableSetInt.eq(Bs_MutableSetInt.intersect({ data: Bs_internalSetInt.ofArray(xs$9) }, { data: Bs_internalSetInt.ofArray(xs$10) @@ -286,7 +286,7 @@ var xs$11 = Array_data_util.randomRange(21, 40); var xs$12 = Array_data_util.randomRange(0, 20); -b("File \"bs_mutable_set_test.ml\", line 120, characters 4-11", Bs_SetIntM.eq(Bs_SetIntM.intersect({ +b("File \"bs_mutable_set_test.ml\", line 120, characters 4-11", Bs_MutableSetInt.eq(Bs_MutableSetInt.intersect({ data: Bs_internalSetInt.ofArray(xs$11) }, { data: Bs_internalSetInt.ofArray(xs$12) @@ -294,7 +294,7 @@ b("File \"bs_mutable_set_test.ml\", line 120, characters 4-11", Bs_SetIntM.eq(Bs data: Bs_internalAVLset.empty })); -b("File \"bs_mutable_set_test.ml\", line 126, characters 4-11", Bs_SetIntM.eq(Bs_SetIntM.intersect({ +b("File \"bs_mutable_set_test.ml\", line 126, characters 4-11", Bs_MutableSetInt.eq(Bs_MutableSetInt.intersect({ data: Bs_internalSetInt.ofArray(/* array */[ 1, 3, @@ -321,13 +321,13 @@ b("File \"bs_mutable_set_test.ml\", line 126, characters 4-11", Bs_SetIntM.eq(Bs var xs$13 = Array_data_util.randomRange(0, 39); -b("File \"bs_mutable_set_test.ml\", line 132, characters 4-11", Bs_SetIntM.eq(Bs_SetIntM.diff(aa$2, bb$2), { +b("File \"bs_mutable_set_test.ml\", line 132, characters 4-11", Bs_MutableSetInt.eq(Bs_MutableSetInt.diff(aa$2, bb$2), { data: Bs_internalSetInt.ofArray(xs$13) })); var xs$14 = Array_data_util.randomRange(101, 120); -b("File \"bs_mutable_set_test.ml\", line 134, characters 4-11", Bs_SetIntM.eq(Bs_SetIntM.diff(bb$2, aa$2), { +b("File \"bs_mutable_set_test.ml\", line 134, characters 4-11", Bs_MutableSetInt.eq(Bs_MutableSetInt.diff(bb$2, aa$2), { data: Bs_internalSetInt.ofArray(xs$14) })); @@ -337,7 +337,7 @@ var xs$16 = Array_data_util.randomRange(0, 20); var xs$17 = Array_data_util.randomRange(21, 40); -b("File \"bs_mutable_set_test.ml\", line 136, characters 4-11", Bs_SetIntM.eq(Bs_SetIntM.diff({ +b("File \"bs_mutable_set_test.ml\", line 136, characters 4-11", Bs_MutableSetInt.eq(Bs_MutableSetInt.diff({ data: Bs_internalSetInt.ofArray(xs$15) }, { data: Bs_internalSetInt.ofArray(xs$16) @@ -351,7 +351,7 @@ var xs$19 = Array_data_util.randomRange(21, 40); var xs$20 = Array_data_util.randomRange(0, 20); -b("File \"bs_mutable_set_test.ml\", line 142, characters 4-11", Bs_SetIntM.eq(Bs_SetIntM.diff({ +b("File \"bs_mutable_set_test.ml\", line 142, characters 4-11", Bs_MutableSetInt.eq(Bs_MutableSetInt.diff({ data: Bs_internalSetInt.ofArray(xs$18) }, { data: Bs_internalSetInt.ofArray(xs$19) @@ -365,7 +365,7 @@ var xs$22 = Array_data_util.randomRange(0, 40); var xs$23 = Array_data_util.randomRange(0, -1); -b("File \"bs_mutable_set_test.ml\", line 149, characters 4-11", Bs_SetIntM.eq(Bs_SetIntM.diff({ +b("File \"bs_mutable_set_test.ml\", line 149, characters 4-11", Bs_MutableSetInt.eq(Bs_MutableSetInt.diff({ data: Bs_internalSetInt.ofArray(xs$21) }, { data: Bs_internalSetInt.ofArray(xs$22) @@ -379,15 +379,15 @@ var a0 = { data: Bs_internalSetInt.ofArray(xs$24) }; -var a1 = Bs_SetIntM.keep(a0, (function (x) { +var a1 = Bs_MutableSetInt.keep(a0, (function (x) { return +(x % 2 === 0); })); -var a2 = Bs_SetIntM.keep(a0, (function (x) { +var a2 = Bs_MutableSetInt.keep(a0, (function (x) { return +(x % 2 !== 0); })); -var match$4 = Bs_SetIntM.partition(a0, (function (x) { +var match$4 = Bs_MutableSetInt.partition(a0, (function (x) { return +(x % 2 === 0); })); @@ -395,9 +395,9 @@ var a4 = match$4[1]; var a3 = match$4[0]; -b("File \"bs_mutable_set_test.ml\", line 164, characters 4-11", Bs_SetIntM.eq(a1, a3)); +b("File \"bs_mutable_set_test.ml\", line 164, characters 4-11", Bs_MutableSetInt.eq(a1, a3)); -b("File \"bs_mutable_set_test.ml\", line 165, characters 4-11", Bs_SetIntM.eq(a2, a4)); +b("File \"bs_mutable_set_test.ml\", line 165, characters 4-11", Bs_MutableSetInt.eq(a2, a4)); b("File \"bs_mutable_set_test.ml\", line 166, characters 4-11", Bs_List.every(/* :: */[ a0, @@ -423,7 +423,7 @@ var v$1 = { }; for(var i$2 = 0; i$2 <= 100000; ++i$2){ - Bs_SetIntM.add(v$1, i$2); + Bs_MutableSetInt.add(v$1, i$2); } b("File \"bs_mutable_set_test.ml\", line 177, characters 4-11", Bs_internalAVLset.checkInvariantInternal(v$1.data)); @@ -440,7 +440,7 @@ var v$2 = { data: Bs_internalAVLset.empty }; -Bs_SetIntM.mergeMany(v$2, u$1); +Bs_MutableSetInt.mergeMany(v$2, u$1); eq("File \"bs_mutable_set_test.ml\", line 187, characters 5-12", Bs_internalAVLset.size(v$2.data), 91); @@ -457,7 +457,7 @@ eq("File \"bs_mutable_set_test.ml\", line 193, characters 5-12", Bs_internalAVLs var u$3 = Array_data_util.randomRange(50000, 80000); for(var i$3 = 0 ,i_finish$1 = u$3.length - 1 | 0; i$3 <= i_finish$1; ++i$3){ - Bs_SetIntM.remove(v$3, i$3); + Bs_MutableSetInt.remove(v$3, i$3); } eq("File \"bs_mutable_set_test.ml\", line 200, characters 5-12", Bs_internalAVLset.size(v$3.data), 70000); @@ -465,7 +465,7 @@ eq("File \"bs_mutable_set_test.ml\", line 200, characters 5-12", Bs_internalAVLs var vv = Array_data_util.randomRange(0, 100000); for(var i$4 = 0 ,i_finish$2 = vv.length - 1 | 0; i$4 <= i_finish$2; ++i$4){ - Bs_SetIntM.remove(v$3, Caml_array.caml_array_get(vv, i$4)); + Bs_MutableSetInt.remove(v$3, Caml_array.caml_array_get(vv, i$4)); } eq("File \"bs_mutable_set_test.ml\", line 206, characters 5-12", Bs_internalAVLset.size(v$3.data), 0); @@ -480,13 +480,13 @@ var v$4 = { data: Bs_internalSetInt.ofArray(xs$25) }; -Bs_SetIntM.remove(v$4, 30); +Bs_MutableSetInt.remove(v$4, 30); -Bs_SetIntM.remove(v$4, 29); +Bs_MutableSetInt.remove(v$4, 29); b("File \"bs_mutable_set_test.ml\", line 213, characters 4-11", +(28 === Bs_internalAVLset.maxUndefined(v$4.data))); -Bs_SetIntM.remove(v$4, 0); +Bs_MutableSetInt.remove(v$4, 0); b("File \"bs_mutable_set_test.ml\", line 215, characters 4-11", +(1 === Bs_internalAVLset.minUndefined(v$4.data))); @@ -495,7 +495,7 @@ eq("File \"bs_mutable_set_test.ml\", line 216, characters 5-12", Bs_internalAVLs var vv$1 = Array_data_util.randomRange(1, 28); for(var i$5 = 0 ,i_finish$3 = vv$1.length - 1 | 0; i$5 <= i_finish$3; ++i$5){ - Bs_SetIntM.remove(v$4, Caml_array.caml_array_get(vv$1, i$5)); + Bs_MutableSetInt.remove(v$4, Caml_array.caml_array_get(vv$1, i$5)); } eq("File \"bs_mutable_set_test.ml\", line 221, characters 5-12", Bs_internalAVLset.size(v$4.data), 0); @@ -599,20 +599,20 @@ var v$5 = { data: Bs_internalSetInt.ofArray(xs$26) }; -var copyV = Bs_SetIntM.keep(v$5, (function (x) { +var copyV = Bs_MutableSetInt.keep(v$5, (function (x) { return +(x % 8 === 0); })); -var match$5 = Bs_SetIntM.partition(v$5, (function (x) { +var match$5 = Bs_MutableSetInt.partition(v$5, (function (x) { return +(x % 8 === 0); })); -var cc$1 = Bs_SetIntM.keep(v$5, (function (x) { +var cc$1 = Bs_MutableSetInt.keep(v$5, (function (x) { return +(x % 8 !== 0); })); for(var i$6 = 0; i$6 <= 200; ++i$6){ - Bs_SetIntM.remove(v$5, i$6); + Bs_MutableSetInt.remove(v$5, i$6); } eq("File \"bs_mutable_set_test.ml\", line 250, characters 5-12", Bs_internalAVLset.size(copyV.data), 126); @@ -623,9 +623,9 @@ eq("File \"bs_mutable_set_test.ml\", line 251, characters 5-12", Bs_internalAVLs eq("File \"bs_mutable_set_test.ml\", line 252, characters 5-12", Bs_internalAVLset.size(v$5.data), 800); -b("File \"bs_mutable_set_test.ml\", line 253, characters 4-11", Bs_SetIntM.eq(copyV, match$5[0])); +b("File \"bs_mutable_set_test.ml\", line 253, characters 4-11", Bs_MutableSetInt.eq(copyV, match$5[0])); -b("File \"bs_mutable_set_test.ml\", line 254, characters 4-11", Bs_SetIntM.eq(cc$1, match$5[1])); +b("File \"bs_mutable_set_test.ml\", line 254, characters 4-11", Bs_MutableSetInt.eq(cc$1, match$5[1])); var xs$27 = Array_data_util.randomRange(0, 1000); @@ -633,19 +633,19 @@ var v$6 = { data: Bs_internalSetInt.ofArray(xs$27) }; -var match$6 = Bs_SetIntM.split(v$6, 400); +var match$6 = Bs_MutableSetInt.split(v$6, 400); var match$7 = match$6[0]; var xs$28 = Array_data_util.randomRange(0, 399); -b("File \"bs_mutable_set_test.ml\", line 259, characters 4-11", Bs_SetIntM.eq(match$7[0], { +b("File \"bs_mutable_set_test.ml\", line 259, characters 4-11", Bs_MutableSetInt.eq(match$7[0], { data: Bs_internalSetInt.ofArray(xs$28) })); var xs$29 = Array_data_util.randomRange(401, 1000); -b("File \"bs_mutable_set_test.ml\", line 260, characters 4-11", Bs_SetIntM.eq(match$7[1], { +b("File \"bs_mutable_set_test.ml\", line 260, characters 4-11", Bs_MutableSetInt.eq(match$7[1], { data: Bs_internalSetInt.ofArray(xs$29) })); @@ -657,7 +657,7 @@ var d$3 = { data: Bs_internalSetInt.ofArray(xs$30) }; -var match$8 = Bs_SetIntM.split(d$3, 1001); +var match$8 = Bs_MutableSetInt.split(d$3, 1001); var match$9 = match$8[0]; @@ -665,7 +665,7 @@ var xs$31 = Bs_Array.makeBy(501, (function (x) { return (x << 1); })); -b("File \"bs_mutable_set_test.ml\", line 263, characters 4-11", Bs_SetIntM.eq(match$9[0], { +b("File \"bs_mutable_set_test.ml\", line 263, characters 4-11", Bs_MutableSetInt.eq(match$9[0], { data: Bs_internalSetInt.ofArray(xs$31) })); @@ -673,7 +673,7 @@ var xs$32 = Bs_Array.makeBy(500, (function (x) { return 1002 + (x << 1) | 0; })); -b("File \"bs_mutable_set_test.ml\", line 264, characters 4-11", Bs_SetIntM.eq(match$9[1], { +b("File \"bs_mutable_set_test.ml\", line 264, characters 4-11", Bs_MutableSetInt.eq(match$9[1], { data: Bs_internalSetInt.ofArray(xs$32) })); @@ -689,11 +689,11 @@ var bb$3 = { data: Bs_internalSetInt.ofArray(xs$34) }; -var cc$2 = Bs_SetIntM.union(aa$3, bb$3); +var cc$2 = Bs_MutableSetInt.union(aa$3, bb$3); var xs$35 = Array_data_util.randomRange(0, 120); -b("File \"bs_mutable_set_test.ml\", line 274, characters 4-11", Bs_SetIntM.eq(cc$2, { +b("File \"bs_mutable_set_test.ml\", line 274, characters 4-11", Bs_MutableSetInt.eq(cc$2, { data: Bs_internalSetInt.ofArray(xs$35) })); @@ -703,7 +703,7 @@ var xs$37 = Array_data_util.randomRange(21, 40); var xs$38 = Array_data_util.randomRange(0, 40); -b("File \"bs_mutable_set_test.ml\", line 276, characters 4-11", Bs_SetIntM.eq(Bs_SetIntM.union({ +b("File \"bs_mutable_set_test.ml\", line 276, characters 4-11", Bs_MutableSetInt.eq(Bs_MutableSetInt.union({ data: Bs_internalSetInt.ofArray(xs$36) }, { data: Bs_internalSetInt.ofArray(xs$37) @@ -711,11 +711,11 @@ b("File \"bs_mutable_set_test.ml\", line 276, characters 4-11", Bs_SetIntM.eq(Bs data: Bs_internalSetInt.ofArray(xs$38) })); -var dd$1 = Bs_SetIntM.intersect(aa$3, bb$3); +var dd$1 = Bs_MutableSetInt.intersect(aa$3, bb$3); var xs$39 = Array_data_util.randomRange(40, 100); -b("File \"bs_mutable_set_test.ml\", line 281, characters 4-11", Bs_SetIntM.eq(dd$1, { +b("File \"bs_mutable_set_test.ml\", line 281, characters 4-11", Bs_MutableSetInt.eq(dd$1, { data: Bs_internalSetInt.ofArray(xs$39) })); @@ -723,7 +723,7 @@ var xs$40 = Array_data_util.randomRange(0, 20); var xs$41 = Array_data_util.randomRange(21, 40); -b("File \"bs_mutable_set_test.ml\", line 282, characters 4-11", Bs_SetIntM.eq(Bs_SetIntM.intersect({ +b("File \"bs_mutable_set_test.ml\", line 282, characters 4-11", Bs_MutableSetInt.eq(Bs_MutableSetInt.intersect({ data: Bs_internalSetInt.ofArray(xs$40) }, { data: Bs_internalSetInt.ofArray(xs$41) @@ -735,7 +735,7 @@ var xs$42 = Array_data_util.randomRange(21, 40); var xs$43 = Array_data_util.randomRange(0, 20); -b("File \"bs_mutable_set_test.ml\", line 288, characters 4-11", Bs_SetIntM.eq(Bs_SetIntM.intersect({ +b("File \"bs_mutable_set_test.ml\", line 288, characters 4-11", Bs_MutableSetInt.eq(Bs_MutableSetInt.intersect({ data: Bs_internalSetInt.ofArray(xs$42) }, { data: Bs_internalSetInt.ofArray(xs$43) @@ -743,7 +743,7 @@ b("File \"bs_mutable_set_test.ml\", line 288, characters 4-11", Bs_SetIntM.eq(Bs data: Bs_internalAVLset.empty })); -b("File \"bs_mutable_set_test.ml\", line 294, characters 4-11", Bs_SetIntM.eq(Bs_SetIntM.intersect({ +b("File \"bs_mutable_set_test.ml\", line 294, characters 4-11", Bs_MutableSetInt.eq(Bs_MutableSetInt.intersect({ data: Bs_internalSetInt.ofArray(/* array */[ 1, 3, @@ -770,13 +770,13 @@ b("File \"bs_mutable_set_test.ml\", line 294, characters 4-11", Bs_SetIntM.eq(Bs var xs$44 = Array_data_util.randomRange(0, 39); -b("File \"bs_mutable_set_test.ml\", line 300, characters 4-11", Bs_SetIntM.eq(Bs_SetIntM.diff(aa$3, bb$3), { +b("File \"bs_mutable_set_test.ml\", line 300, characters 4-11", Bs_MutableSetInt.eq(Bs_MutableSetInt.diff(aa$3, bb$3), { data: Bs_internalSetInt.ofArray(xs$44) })); var xs$45 = Array_data_util.randomRange(101, 120); -b("File \"bs_mutable_set_test.ml\", line 302, characters 4-11", Bs_SetIntM.eq(Bs_SetIntM.diff(bb$3, aa$3), { +b("File \"bs_mutable_set_test.ml\", line 302, characters 4-11", Bs_MutableSetInt.eq(Bs_MutableSetInt.diff(bb$3, aa$3), { data: Bs_internalSetInt.ofArray(xs$45) })); @@ -786,7 +786,7 @@ var xs$47 = Array_data_util.randomRange(0, 20); var xs$48 = Array_data_util.randomRange(21, 40); -b("File \"bs_mutable_set_test.ml\", line 304, characters 4-11", Bs_SetIntM.eq(Bs_SetIntM.diff({ +b("File \"bs_mutable_set_test.ml\", line 304, characters 4-11", Bs_MutableSetInt.eq(Bs_MutableSetInt.diff({ data: Bs_internalSetInt.ofArray(xs$46) }, { data: Bs_internalSetInt.ofArray(xs$47) @@ -800,7 +800,7 @@ var xs$50 = Array_data_util.randomRange(21, 40); var xs$51 = Array_data_util.randomRange(0, 20); -b("File \"bs_mutable_set_test.ml\", line 310, characters 4-11", Bs_SetIntM.eq(Bs_SetIntM.diff({ +b("File \"bs_mutable_set_test.ml\", line 310, characters 4-11", Bs_MutableSetInt.eq(Bs_MutableSetInt.diff({ data: Bs_internalSetInt.ofArray(xs$49) }, { data: Bs_internalSetInt.ofArray(xs$50) @@ -814,7 +814,7 @@ var xs$53 = Array_data_util.randomRange(0, 40); var xs$54 = Array_data_util.randomRange(0, -1); -b("File \"bs_mutable_set_test.ml\", line 317, characters 4-11", Bs_SetIntM.eq(Bs_SetIntM.diff({ +b("File \"bs_mutable_set_test.ml\", line 317, characters 4-11", Bs_MutableSetInt.eq(Bs_MutableSetInt.diff({ data: Bs_internalSetInt.ofArray(xs$52) }, { data: Bs_internalSetInt.ofArray(xs$53) @@ -834,15 +834,15 @@ var A = 0; var L = 0; -var empty = Bs_SetIntM.make; +var empty = Bs_MutableSetInt.make; -var ofArray = Bs_SetIntM.ofArray; +var ofArray = Bs_MutableSetInt.ofArray; -var $plus$plus = Bs_SetIntM.union; +var $plus$plus = Bs_MutableSetInt.union; -var f = Bs_SetIntM.ofArray; +var f = Bs_MutableSetInt.ofArray; -var $eq$tilde = Bs_SetIntM.eq; +var $eq$tilde = Bs_MutableSetInt.eq; exports.suites = suites; exports.test_id = test_id; diff --git a/jscomp/test/bs_poly_mutable_map_test.js b/jscomp/test/bs_poly_mutable_map_test.js index 0b4a6f5078..341dbc7a10 100644 --- a/jscomp/test/bs_poly_mutable_map_test.js +++ b/jscomp/test/bs_poly_mutable_map_test.js @@ -2,8 +2,8 @@ var Mt = require("./mt.js"); var Bs_Set = require("../../lib/js/bs_Set.js"); -var Bs_MapM = require("../../lib/js/bs_MapM.js"); var Bs_Array = require("../../lib/js/bs_Array.js"); +var Bs_MutableMap = require("../../lib/js/bs_MutableMap.js"); var Caml_primitive = require("../../lib/js/caml_primitive.js"); var Array_data_util = require("./array_data_util.js"); var Bs_internalAVLtree = require("../../lib/js/bs_internalAVLtree.js"); @@ -23,7 +23,7 @@ function b(loc, v) { var Icmp = /* module */[/* cmp */Caml_primitive.caml_int_compare]; function f(x) { - return Bs_MapM.ofArray(x, Icmp); + return Bs_MutableMap.ofArray(x, Icmp); } function ff(x) { @@ -41,13 +41,13 @@ function randomRange(i, j) { var x = randomRange(0, 10); -var a0 = Bs_MapM.ofArray(x, Icmp); +var a0 = Bs_MutableMap.ofArray(x, Icmp); -Bs_MapM.set(a0, 3, 33); +Bs_MutableMap.set(a0, 3, 33); -eq("File \"bs_poly_mutable_map_test.ml\", line 28, characters 7-14", Bs_MapM.getExn(a0, 3), 33); +eq("File \"bs_poly_mutable_map_test.ml\", line 28, characters 7-14", Bs_MutableMap.getExn(a0, 3), 33); -Bs_MapM.removeMany(a0, /* array */[ +Bs_MutableMap.removeMany(a0, /* array */[ 7, 8, 0, @@ -66,7 +66,7 @@ eq("File \"bs_poly_mutable_map_test.ml\", line 30, characters 7-14", Bs_internal 10 ]); -Bs_MapM.removeMany(a0, Array_data_util.randomRange(0, 100)); +Bs_MutableMap.removeMany(a0, Array_data_util.randomRange(0, 100)); b("File \"bs_poly_mutable_map_test.ml\", line 32, characters 6-13", Bs_internalAVLtree.isEmpty(a0.data)); diff --git a/jscomp/test/bs_poly_mutable_set_test.js b/jscomp/test/bs_poly_mutable_set_test.js index cfc1bd5991..1e87a73951 100644 --- a/jscomp/test/bs_poly_mutable_set_test.js +++ b/jscomp/test/bs_poly_mutable_set_test.js @@ -2,8 +2,8 @@ var Mt = require("./mt.js"); var Bs_List = require("../../lib/js/bs_List.js"); -var Bs_SetM = require("../../lib/js/bs_SetM.js"); var Bs_Array = require("../../lib/js/bs_Array.js"); +var Bs_MutableSet = require("../../lib/js/bs_MutableSet.js"); var Caml_primitive = require("../../lib/js/caml_primitive.js"); var Array_data_util = require("./array_data_util.js"); var Bs_internalAVLset = require("../../lib/js/bs_internalAVLset.js"); @@ -23,7 +23,7 @@ function b(loc, x) { var IntCmp = /* module */[/* cmp */Caml_primitive.caml_int_compare]; function ofArray(param) { - return Bs_SetM.ofArray(param, IntCmp); + return Bs_MutableSet.ofArray(param, IntCmp); } function empty() { @@ -35,13 +35,13 @@ function empty() { var u = ofArray(Array_data_util.range(0, 30)); -b("File \"bs_poly_mutable_set_test.ml\", line 18, characters 4-11", Bs_SetM.removeCheck(u, 0)); +b("File \"bs_poly_mutable_set_test.ml\", line 18, characters 4-11", Bs_MutableSet.removeCheck(u, 0)); -b("File \"bs_poly_mutable_set_test.ml\", line 19, characters 4-11", 1 - Bs_SetM.removeCheck(u, 0)); +b("File \"bs_poly_mutable_set_test.ml\", line 19, characters 4-11", 1 - Bs_MutableSet.removeCheck(u, 0)); -b("File \"bs_poly_mutable_set_test.ml\", line 20, characters 4-11", Bs_SetM.removeCheck(u, 30)); +b("File \"bs_poly_mutable_set_test.ml\", line 20, characters 4-11", Bs_MutableSet.removeCheck(u, 30)); -b("File \"bs_poly_mutable_set_test.ml\", line 21, characters 4-11", Bs_SetM.removeCheck(u, 20)); +b("File \"bs_poly_mutable_set_test.ml\", line 21, characters 4-11", Bs_MutableSet.removeCheck(u, 20)); eq("File \"bs_poly_mutable_set_test.ml\", line 22, characters 5-12", Bs_internalAVLset.size(u.data), 28); @@ -51,68 +51,68 @@ b("File \"bs_poly_mutable_set_test.ml\", line 24, characters 4-11", +(29 === Bs_ b("File \"bs_poly_mutable_set_test.ml\", line 25, characters 4-11", +(1 === Bs_internalAVLset.minUndefined(u.data))); -Bs_SetM.add(u, 3); +Bs_MutableSet.add(u, 3); for(var i = 0 ,i_finish = r.length - 1 | 0; i <= i_finish; ++i){ - Bs_SetM.remove(u, r[i]); + Bs_MutableSet.remove(u, r[i]); } b("File \"bs_poly_mutable_set_test.ml\", line 30, characters 4-11", Bs_internalAVLset.isEmpty(u.data)); -Bs_SetM.add(u, 0); +Bs_MutableSet.add(u, 0); -Bs_SetM.add(u, 1); +Bs_MutableSet.add(u, 1); -Bs_SetM.add(u, 2); +Bs_MutableSet.add(u, 2); -Bs_SetM.add(u, 0); +Bs_MutableSet.add(u, 0); eq("File \"bs_poly_mutable_set_test.ml\", line 35, characters 5-12", Bs_internalAVLset.size(u.data), 3); b("File \"bs_poly_mutable_set_test.ml\", line 36, characters 4-11", 1 - Bs_internalAVLset.isEmpty(u.data)); for(var i$1 = 0; i$1 <= 3; ++i$1){ - Bs_SetM.remove(u, i$1); + Bs_MutableSet.remove(u, i$1); } b("File \"bs_poly_mutable_set_test.ml\", line 40, characters 4-11", Bs_internalAVLset.isEmpty(u.data)); -Bs_SetM.mergeMany(u, Array_data_util.randomRange(0, 20000)); +Bs_MutableSet.mergeMany(u, Array_data_util.randomRange(0, 20000)); -Bs_SetM.mergeMany(u, Array_data_util.randomRange(0, 200)); +Bs_MutableSet.mergeMany(u, Array_data_util.randomRange(0, 200)); eq("File \"bs_poly_mutable_set_test.ml\", line 43, characters 5-12", Bs_internalAVLset.size(u.data), 20001); -Bs_SetM.removeMany(u, Array_data_util.randomRange(0, 200)); +Bs_MutableSet.removeMany(u, Array_data_util.randomRange(0, 200)); eq("File \"bs_poly_mutable_set_test.ml\", line 45, characters 5-12", Bs_internalAVLset.size(u.data), 19800); -Bs_SetM.removeMany(u, Array_data_util.randomRange(0, 1000)); +Bs_MutableSet.removeMany(u, Array_data_util.randomRange(0, 1000)); eq("File \"bs_poly_mutable_set_test.ml\", line 47, characters 5-12", Bs_internalAVLset.size(u.data), 19000); -Bs_SetM.removeMany(u, Array_data_util.randomRange(0, 1000)); +Bs_MutableSet.removeMany(u, Array_data_util.randomRange(0, 1000)); eq("File \"bs_poly_mutable_set_test.ml\", line 49, characters 5-12", Bs_internalAVLset.size(u.data), 19000); -Bs_SetM.removeMany(u, Array_data_util.randomRange(1000, 10000)); +Bs_MutableSet.removeMany(u, Array_data_util.randomRange(1000, 10000)); eq("File \"bs_poly_mutable_set_test.ml\", line 51, characters 5-12", Bs_internalAVLset.size(u.data), 10000); -Bs_SetM.removeMany(u, Array_data_util.randomRange(10000, 19999)); +Bs_MutableSet.removeMany(u, Array_data_util.randomRange(10000, 19999)); eq("File \"bs_poly_mutable_set_test.ml\", line 53, characters 5-12", Bs_internalAVLset.size(u.data), 1); -b("File \"bs_poly_mutable_set_test.ml\", line 54, characters 4-11", Bs_SetM.has(u, 20000)); +b("File \"bs_poly_mutable_set_test.ml\", line 54, characters 4-11", Bs_MutableSet.has(u, 20000)); -Bs_SetM.removeMany(u, Array_data_util.randomRange(10000, 30000)); +Bs_MutableSet.removeMany(u, Array_data_util.randomRange(10000, 30000)); b("File \"bs_poly_mutable_set_test.ml\", line 56, characters 4-11", Bs_internalAVLset.isEmpty(u.data)); var v = ofArray(Array_data_util.randomRange(1000, 2000)); var bs = Bs_Array.map(Array_data_util.randomRange(500, 1499), (function (x) { - return Bs_SetM.removeCheck(v, x); + return Bs_MutableSet.removeCheck(v, x); })); var indeedRemoved = Bs_Array.reduce(bs, 0, (function (acc, x) { @@ -128,7 +128,7 @@ eq("File \"bs_poly_mutable_set_test.ml\", line 63, characters 5-12", indeedRemov eq("File \"bs_poly_mutable_set_test.ml\", line 64, characters 5-12", Bs_internalAVLset.size(v.data), 501); var cs = Bs_Array.map(Array_data_util.randomRange(500, 2000), (function (x) { - return Bs_SetM.addCheck(v, x); + return Bs_MutableSet.addCheck(v, x); })); var indeedAded = Bs_Array.reduce(cs, 0, (function (acc, x) { @@ -158,7 +158,7 @@ eq("File \"bs_poly_mutable_set_test.ml\", line 72, characters 5-12", Bs_internal eq("File \"bs_poly_mutable_set_test.ml\", line 73, characters 5-12", Bs_internalAVLset.maxUndefined(v.data), 2000); -eq("File \"bs_poly_mutable_set_test.ml\", line 74, characters 5-12", Bs_SetM.reduce(v, 0, (function (x, y) { +eq("File \"bs_poly_mutable_set_test.ml\", line 74, characters 5-12", Bs_MutableSet.reduce(v, 0, (function (x, y) { return x + y | 0; })), 1876250); @@ -172,11 +172,11 @@ eq("File \"bs_poly_mutable_set_test.ml\", line 76, characters 5-12", Bs_internal b("File \"bs_poly_mutable_set_test.ml\", line 77, characters 4-11", Bs_internalAVLset.checkInvariantInternal(v.data)); -eq("File \"bs_poly_mutable_set_test.ml\", line 78, characters 5-12", Bs_SetM.get(v, 3), /* None */0); +eq("File \"bs_poly_mutable_set_test.ml\", line 78, characters 5-12", Bs_MutableSet.get(v, 3), /* None */0); -eq("File \"bs_poly_mutable_set_test.ml\", line 79, characters 5-12", Bs_SetM.get(v, 1200), /* Some */[1200]); +eq("File \"bs_poly_mutable_set_test.ml\", line 79, characters 5-12", Bs_MutableSet.get(v, 1200), /* Some */[1200]); -var match = Bs_SetM.split(v, 1000); +var match = Bs_MutableSet.split(v, 1000); var match$1 = match[0]; @@ -194,19 +194,19 @@ b("File \"bs_poly_mutable_set_test.ml\", line 83, characters 4-11", Bs_Array.eq( return +(x === y); }))); -b("File \"bs_poly_mutable_set_test.ml\", line 84, characters 5-12", Bs_SetM.subset(aa, v)); +b("File \"bs_poly_mutable_set_test.ml\", line 84, characters 5-12", Bs_MutableSet.subset(aa, v)); -b("File \"bs_poly_mutable_set_test.ml\", line 85, characters 4-11", Bs_SetM.subset(bb, v)); +b("File \"bs_poly_mutable_set_test.ml\", line 85, characters 4-11", Bs_MutableSet.subset(bb, v)); -var d$1 = Bs_SetM.intersect(aa, bb); +var d$1 = Bs_MutableSet.intersect(aa, bb); b("File \"bs_poly_mutable_set_test.ml\", line 86, characters 4-11", Bs_internalAVLset.isEmpty(d$1.data)); -var c = Bs_SetM.removeCheck(v, 1000); +var c = Bs_MutableSet.removeCheck(v, 1000); b("File \"bs_poly_mutable_set_test.ml\", line 88, characters 4-11", c); -var match$2 = Bs_SetM.split(v, 1000); +var match$2 = Bs_MutableSet.split(v, 1000); var match$3 = match$2[0]; @@ -224,11 +224,11 @@ b("File \"bs_poly_mutable_set_test.ml\", line 92, characters 4-11", Bs_Array.eq( return +(x === y); }))); -b("File \"bs_poly_mutable_set_test.ml\", line 93, characters 5-12", Bs_SetM.subset(aa$1, v)); +b("File \"bs_poly_mutable_set_test.ml\", line 93, characters 5-12", Bs_MutableSet.subset(aa$1, v)); -b("File \"bs_poly_mutable_set_test.ml\", line 94, characters 4-11", Bs_SetM.subset(bb$1, v)); +b("File \"bs_poly_mutable_set_test.ml\", line 94, characters 4-11", Bs_MutableSet.subset(bb$1, v)); -var d$2 = Bs_SetM.intersect(aa$1, bb$1); +var d$2 = Bs_MutableSet.intersect(aa$1, bb$1); b("File \"bs_poly_mutable_set_test.ml\", line 95, characters 4-11", Bs_internalAVLset.isEmpty(d$2.data)); @@ -236,27 +236,27 @@ var aa$2 = ofArray(Array_data_util.randomRange(0, 100)); var bb$2 = ofArray(Array_data_util.randomRange(40, 120)); -var cc = Bs_SetM.union(aa$2, bb$2); +var cc = Bs_MutableSet.union(aa$2, bb$2); -b("File \"bs_poly_mutable_set_test.ml\", line 104, characters 4-11", Bs_SetM.eq(cc, ofArray(Array_data_util.randomRange(0, 120)))); +b("File \"bs_poly_mutable_set_test.ml\", line 104, characters 4-11", Bs_MutableSet.eq(cc, ofArray(Array_data_util.randomRange(0, 120)))); -b("File \"bs_poly_mutable_set_test.ml\", line 106, characters 4-11", Bs_SetM.eq(Bs_SetM.union(ofArray(Array_data_util.randomRange(0, 20)), ofArray(Array_data_util.randomRange(21, 40))), ofArray(Array_data_util.randomRange(0, 40)))); +b("File \"bs_poly_mutable_set_test.ml\", line 106, characters 4-11", Bs_MutableSet.eq(Bs_MutableSet.union(ofArray(Array_data_util.randomRange(0, 20)), ofArray(Array_data_util.randomRange(21, 40))), ofArray(Array_data_util.randomRange(0, 40)))); -var dd = Bs_SetM.intersect(aa$2, bb$2); +var dd = Bs_MutableSet.intersect(aa$2, bb$2); -b("File \"bs_poly_mutable_set_test.ml\", line 111, characters 4-11", Bs_SetM.eq(dd, ofArray(Array_data_util.randomRange(40, 100)))); +b("File \"bs_poly_mutable_set_test.ml\", line 111, characters 4-11", Bs_MutableSet.eq(dd, ofArray(Array_data_util.randomRange(40, 100)))); -b("File \"bs_poly_mutable_set_test.ml\", line 112, characters 4-11", Bs_SetM.eq(Bs_SetM.intersect(ofArray(Array_data_util.randomRange(0, 20)), ofArray(Array_data_util.randomRange(21, 40))), { +b("File \"bs_poly_mutable_set_test.ml\", line 112, characters 4-11", Bs_MutableSet.eq(Bs_MutableSet.intersect(ofArray(Array_data_util.randomRange(0, 20)), ofArray(Array_data_util.randomRange(21, 40))), { cmp: IntCmp[/* cmp */0], data: Bs_internalAVLset.empty })); -b("File \"bs_poly_mutable_set_test.ml\", line 118, characters 4-11", Bs_SetM.eq(Bs_SetM.intersect(ofArray(Array_data_util.randomRange(21, 40)), ofArray(Array_data_util.randomRange(0, 20))), { +b("File \"bs_poly_mutable_set_test.ml\", line 118, characters 4-11", Bs_MutableSet.eq(Bs_MutableSet.intersect(ofArray(Array_data_util.randomRange(21, 40)), ofArray(Array_data_util.randomRange(0, 20))), { cmp: IntCmp[/* cmp */0], data: Bs_internalAVLset.empty })); -b("File \"bs_poly_mutable_set_test.ml\", line 124, characters 4-11", Bs_SetM.eq(Bs_SetM.intersect(ofArray(/* array */[ +b("File \"bs_poly_mutable_set_test.ml\", line 124, characters 4-11", Bs_MutableSet.eq(Bs_MutableSet.intersect(ofArray(/* array */[ 1, 3, 4, @@ -275,27 +275,27 @@ b("File \"bs_poly_mutable_set_test.ml\", line 124, characters 4-11", Bs_SetM.eq( 5 ]))); -b("File \"bs_poly_mutable_set_test.ml\", line 130, characters 4-11", Bs_SetM.eq(Bs_SetM.diff(aa$2, bb$2), ofArray(Array_data_util.randomRange(0, 39)))); +b("File \"bs_poly_mutable_set_test.ml\", line 130, characters 4-11", Bs_MutableSet.eq(Bs_MutableSet.diff(aa$2, bb$2), ofArray(Array_data_util.randomRange(0, 39)))); -b("File \"bs_poly_mutable_set_test.ml\", line 132, characters 4-11", Bs_SetM.eq(Bs_SetM.diff(bb$2, aa$2), ofArray(Array_data_util.randomRange(101, 120)))); +b("File \"bs_poly_mutable_set_test.ml\", line 132, characters 4-11", Bs_MutableSet.eq(Bs_MutableSet.diff(bb$2, aa$2), ofArray(Array_data_util.randomRange(101, 120)))); -b("File \"bs_poly_mutable_set_test.ml\", line 134, characters 4-11", Bs_SetM.eq(Bs_SetM.diff(ofArray(Array_data_util.randomRange(21, 40)), ofArray(Array_data_util.randomRange(0, 20))), ofArray(Array_data_util.randomRange(21, 40)))); +b("File \"bs_poly_mutable_set_test.ml\", line 134, characters 4-11", Bs_MutableSet.eq(Bs_MutableSet.diff(ofArray(Array_data_util.randomRange(21, 40)), ofArray(Array_data_util.randomRange(0, 20))), ofArray(Array_data_util.randomRange(21, 40)))); -b("File \"bs_poly_mutable_set_test.ml\", line 140, characters 4-11", Bs_SetM.eq(Bs_SetM.diff(ofArray(Array_data_util.randomRange(0, 20)), ofArray(Array_data_util.randomRange(21, 40))), ofArray(Array_data_util.randomRange(0, 20)))); +b("File \"bs_poly_mutable_set_test.ml\", line 140, characters 4-11", Bs_MutableSet.eq(Bs_MutableSet.diff(ofArray(Array_data_util.randomRange(0, 20)), ofArray(Array_data_util.randomRange(21, 40))), ofArray(Array_data_util.randomRange(0, 20)))); -b("File \"bs_poly_mutable_set_test.ml\", line 147, characters 4-11", Bs_SetM.eq(Bs_SetM.diff(ofArray(Array_data_util.randomRange(0, 20)), ofArray(Array_data_util.randomRange(0, 40))), ofArray(Array_data_util.randomRange(0, -1)))); +b("File \"bs_poly_mutable_set_test.ml\", line 147, characters 4-11", Bs_MutableSet.eq(Bs_MutableSet.diff(ofArray(Array_data_util.randomRange(0, 20)), ofArray(Array_data_util.randomRange(0, 40))), ofArray(Array_data_util.randomRange(0, -1)))); var a0 = ofArray(Array_data_util.randomRange(0, 1000)); -var a1 = Bs_SetM.keep(a0, (function (x) { +var a1 = Bs_MutableSet.keep(a0, (function (x) { return +(x % 2 === 0); })); -var a2 = Bs_SetM.keep(a0, (function (x) { +var a2 = Bs_MutableSet.keep(a0, (function (x) { return +(x % 2 !== 0); })); -var match$4 = Bs_SetM.partition(a0, (function (x) { +var match$4 = Bs_MutableSet.partition(a0, (function (x) { return +(x % 2 === 0); })); @@ -303,9 +303,9 @@ var a4 = match$4[1]; var a3 = match$4[0]; -b("File \"bs_poly_mutable_set_test.ml\", line 162, characters 4-11", Bs_SetM.eq(a1, a3)); +b("File \"bs_poly_mutable_set_test.ml\", line 162, characters 4-11", Bs_MutableSet.eq(a1, a3)); -b("File \"bs_poly_mutable_set_test.ml\", line 163, characters 4-11", Bs_SetM.eq(a2, a4)); +b("File \"bs_poly_mutable_set_test.ml\", line 163, characters 4-11", Bs_MutableSet.eq(a2, a4)); b("File \"bs_poly_mutable_set_test.ml\", line 164, characters 4-11", Bs_List.every(/* :: */[ a0, @@ -336,11 +336,11 @@ var A = 0; var L = 0; -var $plus$plus = Bs_SetM.union; +var $plus$plus = Bs_MutableSet.union; var f = ofArray; -var $eq$tilde = Bs_SetM.eq; +var $eq$tilde = Bs_MutableSet.eq; exports.suites = suites; exports.test_id = test_id; diff --git a/lib/js/bs_MutableMap.js b/lib/js/bs_MutableMap.js new file mode 100644 index 0000000000..8342b17d03 --- /dev/null +++ b/lib/js/bs_MutableMap.js @@ -0,0 +1,364 @@ +'use strict'; + +var Bs_internalAVLtree = require("./bs_internalAVLtree.js"); + +function removeMutateAux(nt, x, cmp) { + var k = nt.key; + var c = cmp(x, k); + if (c) { + if (c < 0) { + var match = nt.left; + if (match !== null) { + nt.left = removeMutateAux(match, x, cmp); + return Bs_internalAVLtree.balMutate(nt); + } else { + return nt; + } + } else { + var match$1 = nt.right; + if (match$1 !== null) { + nt.right = removeMutateAux(match$1, x, cmp); + return Bs_internalAVLtree.balMutate(nt); + } else { + return nt; + } + } + } else { + var l = nt.left; + var r = nt.right; + if (l !== null) { + if (r !== null) { + nt.right = Bs_internalAVLtree.removeMinAuxWithRootMutate(nt, r); + return Bs_internalAVLtree.balMutate(nt); + } else { + return l; + } + } else if (r !== null) { + return r; + } else { + return l; + } + } +} + +function remove(d, k) { + var oldRoot = d.data; + if (oldRoot !== null) { + var newRoot = removeMutateAux(oldRoot, k, d.cmp); + if (newRoot !== oldRoot) { + d.data = newRoot; + return /* () */0; + } else { + return 0; + } + } else { + return /* () */0; + } +} + +function removeArrayMutateAux(_t, xs, _i, len, cmp) { + while(true) { + var i = _i; + var t = _t; + if (i < len) { + var ele = xs[i]; + var u = removeMutateAux(t, ele, cmp); + if (u !== null) { + _i = i + 1 | 0; + _t = u; + continue ; + + } else { + return Bs_internalAVLtree.empty; + } + } else { + return t; + } + }; +} + +function removeMany(d, xs) { + var oldRoot = d.data; + if (oldRoot !== null) { + var len = xs.length; + var newRoot = removeArrayMutateAux(oldRoot, xs, 0, len, d.cmp); + if (newRoot !== oldRoot) { + d.data = newRoot; + return /* () */0; + } else { + return 0; + } + } else { + return /* () */0; + } +} + +function updateDone(t, x, f, cmp) { + if (t !== null) { + var k = t.key; + var c = cmp(x, k); + if (c) { + var l = t.left; + var r = t.right; + if (c < 0) { + var ll = updateDone(l, x, f, cmp); + t.left = ll; + } else { + t.right = updateDone(r, x, f, cmp); + } + return Bs_internalAVLtree.balMutate(t); + } else { + var match = f(/* Some */[t.value]); + if (match) { + t.value = match[0]; + return t; + } else { + var l$1 = t.left; + var r$1 = t.right; + if (l$1 !== null) { + if (r$1 !== null) { + t.right = Bs_internalAVLtree.removeMinAuxWithRootMutate(t, r$1); + return Bs_internalAVLtree.balMutate(t); + } else { + return l$1; + } + } else if (r$1 !== null) { + return r$1; + } else { + return l$1; + } + } + } + } else { + var match$1 = f(/* None */0); + if (match$1) { + return Bs_internalAVLtree.singleton(x, match$1[0]); + } else { + return t; + } + } +} + +function update(t, x, f) { + var oldRoot = t.data; + var newRoot = updateDone(oldRoot, x, f, t.cmp); + if (newRoot !== oldRoot) { + t.data = newRoot; + return /* () */0; + } else { + return 0; + } +} + +function make(dict) { + return { + cmp: dict[/* cmp */0], + data: Bs_internalAVLtree.empty + }; +} + +function clear(m) { + m.data = Bs_internalAVLtree.empty; + return /* () */0; +} + +function isEmpty(d) { + return Bs_internalAVLtree.isEmpty(d.data); +} + +function minKey(m) { + return Bs_internalAVLtree.minKey(m.data); +} + +function minKeyUndefined(m) { + return Bs_internalAVLtree.minKeyUndefined(m.data); +} + +function maxKey(m) { + return Bs_internalAVLtree.maxKey(m.data); +} + +function maxKeyUndefined(m) { + return Bs_internalAVLtree.maxKeyUndefined(m.data); +} + +function minimum(m) { + return Bs_internalAVLtree.minimum(m.data); +} + +function minUndefined(m) { + return Bs_internalAVLtree.minUndefined(m.data); +} + +function maximum(m) { + return Bs_internalAVLtree.maximum(m.data); +} + +function maxUndefined(m) { + return Bs_internalAVLtree.maxUndefined(m.data); +} + +function forEach(d, f) { + return Bs_internalAVLtree.forEach(d.data, f); +} + +function reduce(d, acc, cb) { + return Bs_internalAVLtree.reduce(d.data, acc, cb); +} + +function every(d, p) { + return Bs_internalAVLtree.every(d.data, p); +} + +function some(d, p) { + return Bs_internalAVLtree.some(d.data, p); +} + +function size(d) { + return Bs_internalAVLtree.size(d.data); +} + +function toList(d) { + return Bs_internalAVLtree.toList(d.data); +} + +function toArray(d) { + return Bs_internalAVLtree.toArray(d.data); +} + +function keysToArray(d) { + return Bs_internalAVLtree.keysToArray(d.data); +} + +function valuesToArray(d) { + return Bs_internalAVLtree.valuesToArray(d.data); +} + +function checkInvariantInternal(d) { + return Bs_internalAVLtree.checkInvariantInternal(d.data); +} + +function cmp(m1, m2, cmp$1) { + return Bs_internalAVLtree.cmp(m1.data, m2.data, m1.cmp, cmp$1); +} + +function eq(m1, m2, cmp) { + return Bs_internalAVLtree.eq(m1.data, m2.data, m1.cmp, cmp); +} + +function map(m, f) { + return { + cmp: m.cmp, + data: Bs_internalAVLtree.map(m.data, f) + }; +} + +function mapWithKey(m, f) { + return { + cmp: m.cmp, + data: Bs_internalAVLtree.mapWithKey(m.data, f) + }; +} + +function get(m, x) { + return Bs_internalAVLtree.get(m.data, x, m.cmp); +} + +function getUndefined(m, x) { + return Bs_internalAVLtree.getUndefined(m.data, x, m.cmp); +} + +function getWithDefault(m, x, def) { + return Bs_internalAVLtree.getWithDefault(m.data, x, def, m.cmp); +} + +function getExn(m, x) { + return Bs_internalAVLtree.getExn(m.data, x, m.cmp); +} + +function has(m, x) { + return Bs_internalAVLtree.has(m.data, x, m.cmp); +} + +function ofArray(data, dict) { + var cmp = dict[/* cmp */0]; + return { + cmp: cmp, + data: Bs_internalAVLtree.ofArray(data, cmp) + }; +} + +function set(m, e, v) { + var oldRoot = m.data; + var newRoot = Bs_internalAVLtree.updateMutate(oldRoot, e, v, m.cmp); + if (newRoot !== oldRoot) { + m.data = newRoot; + return /* () */0; + } else { + return 0; + } +} + +function mergeArrayAux(t, xs, cmp) { + var v = t; + for(var i = 0 ,i_finish = xs.length - 1 | 0; i <= i_finish; ++i){ + var match = xs[i]; + v = Bs_internalAVLtree.updateMutate(v, match[0], match[1], cmp); + } + return v; +} + +function mergeMany(d, xs) { + var oldRoot = d.data; + var newRoot = mergeArrayAux(oldRoot, xs, d.cmp); + if (newRoot !== oldRoot) { + d.data = newRoot; + return /* () */0; + } else { + return 0; + } +} + +var Int = 0; + +var $$String = 0; + +exports.Int = Int; +exports.$$String = $$String; +exports.make = make; +exports.clear = clear; +exports.isEmpty = isEmpty; +exports.has = has; +exports.cmp = cmp; +exports.eq = eq; +exports.forEach = forEach; +exports.reduce = reduce; +exports.every = every; +exports.some = some; +exports.size = size; +exports.toList = toList; +exports.toArray = toArray; +exports.ofArray = ofArray; +exports.keysToArray = keysToArray; +exports.valuesToArray = valuesToArray; +exports.minKey = minKey; +exports.minKeyUndefined = minKeyUndefined; +exports.maxKey = maxKey; +exports.maxKeyUndefined = maxKeyUndefined; +exports.minimum = minimum; +exports.minUndefined = minUndefined; +exports.maximum = maximum; +exports.maxUndefined = maxUndefined; +exports.get = get; +exports.getUndefined = getUndefined; +exports.getWithDefault = getWithDefault; +exports.getExn = getExn; +exports.checkInvariantInternal = checkInvariantInternal; +exports.remove = remove; +exports.removeMany = removeMany; +exports.set = set; +exports.update = update; +exports.mergeMany = mergeMany; +exports.map = map; +exports.mapWithKey = mapWithKey; +/* No side effect */ diff --git a/lib/js/bs_MutableMapInt.js b/lib/js/bs_MutableMapInt.js new file mode 100644 index 0000000000..fded5259c1 --- /dev/null +++ b/lib/js/bs_MutableMapInt.js @@ -0,0 +1,333 @@ +'use strict'; + +var Bs_internalMapInt = require("./bs_internalMapInt.js"); +var Bs_internalAVLtree = require("./bs_internalAVLtree.js"); + +function make() { + return { + data: Bs_internalAVLtree.empty + }; +} + +function isEmpty(m) { + return Bs_internalAVLtree.isEmpty(m.data); +} + +function clear(m) { + m.data = Bs_internalAVLtree.empty; + return /* () */0; +} + +function minKeyUndefined(m) { + return Bs_internalAVLtree.minKeyUndefined(m.data); +} + +function minKey(m) { + return Bs_internalAVLtree.minKey(m.data); +} + +function maxKeyUndefined(m) { + return Bs_internalAVLtree.maxKeyUndefined(m.data); +} + +function maxKey(m) { + return Bs_internalAVLtree.maxKey(m.data); +} + +function minimum(m) { + return Bs_internalAVLtree.minimum(m.data); +} + +function minUndefined(m) { + return Bs_internalAVLtree.minUndefined(m.data); +} + +function maximum(m) { + return Bs_internalAVLtree.maximum(m.data); +} + +function maxUndefined(m) { + return Bs_internalAVLtree.maxUndefined(m.data); +} + +function set(m, k, v) { + var old_data = m.data; + var v$1 = Bs_internalMapInt.addMutate(old_data, k, v); + if (v$1 !== old_data) { + m.data = v$1; + return /* () */0; + } else { + return 0; + } +} + +function forEach(d, f) { + return Bs_internalAVLtree.forEach(d.data, f); +} + +function map(d, f) { + return { + data: Bs_internalAVLtree.map(d.data, f) + }; +} + +function mapWithKey(d, f) { + return { + data: Bs_internalAVLtree.mapWithKey(d.data, f) + }; +} + +function reduce(d, acc, f) { + return Bs_internalAVLtree.reduce(d.data, acc, f); +} + +function every(d, f) { + return Bs_internalAVLtree.every(d.data, f); +} + +function some(d, f) { + return Bs_internalAVLtree.some(d.data, f); +} + +function size(d) { + return Bs_internalAVLtree.size(d.data); +} + +function toList(d) { + return Bs_internalAVLtree.toList(d.data); +} + +function toArray(d) { + return Bs_internalAVLtree.toArray(d.data); +} + +function keysToArray(d) { + return Bs_internalAVLtree.keysToArray(d.data); +} + +function valuesToArray(d) { + return Bs_internalAVLtree.valuesToArray(d.data); +} + +function checkInvariantInternal(d) { + return Bs_internalAVLtree.checkInvariantInternal(d.data); +} + +function has(d, v) { + return Bs_internalMapInt.has(d.data, v); +} + +function removeMutateAux(nt, x) { + var k = nt.key; + if (x === k) { + var l = nt.left; + var r = nt.right; + if (l !== null) { + if (r !== null) { + nt.right = Bs_internalAVLtree.removeMinAuxWithRootMutate(nt, r); + return Bs_internalAVLtree.balMutate(nt); + } else { + return l; + } + } else { + return r; + } + } else if (x < k) { + var match = nt.left; + if (match !== null) { + nt.left = removeMutateAux(match, x); + return Bs_internalAVLtree.balMutate(nt); + } else { + return nt; + } + } else { + var match$1 = nt.right; + if (match$1 !== null) { + nt.right = removeMutateAux(match$1, x); + return Bs_internalAVLtree.balMutate(nt); + } else { + return nt; + } + } +} + +function remove(d, v) { + var oldRoot = d.data; + if (oldRoot !== null) { + var newRoot = removeMutateAux(oldRoot, v); + if (newRoot !== oldRoot) { + d.data = newRoot; + return /* () */0; + } else { + return 0; + } + } else { + return /* () */0; + } +} + +function updateDone(t, x, f) { + if (t !== null) { + var k = t.key; + if (k === x) { + var match = f(/* Some */[t.value]); + if (match) { + t.value = match[0]; + return t; + } else { + var l = t.left; + var r = t.right; + if (l !== null) { + if (r !== null) { + t.right = Bs_internalAVLtree.removeMinAuxWithRootMutate(t, r); + return Bs_internalAVLtree.balMutate(t); + } else { + return l; + } + } else { + return r; + } + } + } else { + var l$1 = t.left; + var r$1 = t.right; + if (x < k) { + var ll = updateDone(l$1, x, f); + t.left = ll; + } else { + t.right = updateDone(r$1, x, f); + } + return Bs_internalAVLtree.balMutate(t); + } + } else { + var match$1 = f(/* None */0); + if (match$1) { + return Bs_internalAVLtree.singleton(x, match$1[0]); + } else { + return t; + } + } +} + +function update(t, x, f) { + var oldRoot = t.data; + var newRoot = updateDone(oldRoot, x, f); + if (newRoot !== oldRoot) { + t.data = newRoot; + return /* () */0; + } else { + return 0; + } +} + +function removeArrayMutateAux(_t, xs, _i, len) { + while(true) { + var i = _i; + var t = _t; + if (i < len) { + var ele = xs[i]; + var u = removeMutateAux(t, ele); + if (u !== null) { + _i = i + 1 | 0; + _t = u; + continue ; + + } else { + return Bs_internalAVLtree.empty; + } + } else { + return t; + } + }; +} + +function removeMany(d, xs) { + var oldRoot = d.data; + if (oldRoot !== null) { + var len = xs.length; + var newRoot = removeArrayMutateAux(oldRoot, xs, 0, len); + if (newRoot !== oldRoot) { + d.data = newRoot; + return /* () */0; + } else { + return 0; + } + } else { + return /* () */0; + } +} + +function ofArray(xs) { + return { + data: Bs_internalMapInt.ofArray(xs) + }; +} + +function cmp(d0, d1) { + var partial_arg = d1.data; + var partial_arg$1 = d0.data; + return (function (param) { + return Bs_internalMapInt.cmp(partial_arg$1, partial_arg, param); + }); +} + +function eq(d0, d1) { + var partial_arg = d1.data; + var partial_arg$1 = d0.data; + return (function (param) { + return Bs_internalMapInt.eq(partial_arg$1, partial_arg, param); + }); +} + +function get(d, x) { + return Bs_internalMapInt.get(d.data, x); +} + +function getUndefined(d, x) { + return Bs_internalMapInt.getUndefined(d.data, x); +} + +function getWithDefault(d, x, def) { + return Bs_internalMapInt.getWithDefault(d.data, x, def); +} + +function getExn(d, x) { + return Bs_internalMapInt.getExn(d.data, x); +} + +exports.make = make; +exports.clear = clear; +exports.isEmpty = isEmpty; +exports.has = has; +exports.cmp = cmp; +exports.eq = eq; +exports.forEach = forEach; +exports.reduce = reduce; +exports.every = every; +exports.some = some; +exports.size = size; +exports.toList = toList; +exports.toArray = toArray; +exports.ofArray = ofArray; +exports.keysToArray = keysToArray; +exports.valuesToArray = valuesToArray; +exports.minKey = minKey; +exports.minKeyUndefined = minKeyUndefined; +exports.maxKey = maxKey; +exports.maxKeyUndefined = maxKeyUndefined; +exports.minimum = minimum; +exports.minUndefined = minUndefined; +exports.maximum = maximum; +exports.maxUndefined = maxUndefined; +exports.get = get; +exports.getUndefined = getUndefined; +exports.getWithDefault = getWithDefault; +exports.getExn = getExn; +exports.checkInvariantInternal = checkInvariantInternal; +exports.remove = remove; +exports.removeMany = removeMany; +exports.set = set; +exports.update = update; +exports.map = map; +exports.mapWithKey = mapWithKey; +/* No side effect */ diff --git a/lib/js/bs_MutableMapString.js b/lib/js/bs_MutableMapString.js new file mode 100644 index 0000000000..759d319f4e --- /dev/null +++ b/lib/js/bs_MutableMapString.js @@ -0,0 +1,333 @@ +'use strict'; + +var Bs_internalAVLtree = require("./bs_internalAVLtree.js"); +var Bs_internalMapString = require("./bs_internalMapString.js"); + +function make() { + return { + data: Bs_internalAVLtree.empty + }; +} + +function isEmpty(m) { + return Bs_internalAVLtree.isEmpty(m.data); +} + +function clear(m) { + m.data = Bs_internalAVLtree.empty; + return /* () */0; +} + +function minKeyUndefined(m) { + return Bs_internalAVLtree.minKeyUndefined(m.data); +} + +function minKey(m) { + return Bs_internalAVLtree.minKey(m.data); +} + +function maxKeyUndefined(m) { + return Bs_internalAVLtree.maxKeyUndefined(m.data); +} + +function maxKey(m) { + return Bs_internalAVLtree.maxKey(m.data); +} + +function minimum(m) { + return Bs_internalAVLtree.minimum(m.data); +} + +function minUndefined(m) { + return Bs_internalAVLtree.minUndefined(m.data); +} + +function maximum(m) { + return Bs_internalAVLtree.maximum(m.data); +} + +function maxUndefined(m) { + return Bs_internalAVLtree.maxUndefined(m.data); +} + +function set(m, k, v) { + var old_data = m.data; + var v$1 = Bs_internalMapString.addMutate(old_data, k, v); + if (v$1 !== old_data) { + m.data = v$1; + return /* () */0; + } else { + return 0; + } +} + +function forEach(d, f) { + return Bs_internalAVLtree.forEach(d.data, f); +} + +function map(d, f) { + return { + data: Bs_internalAVLtree.map(d.data, f) + }; +} + +function mapWithKey(d, f) { + return { + data: Bs_internalAVLtree.mapWithKey(d.data, f) + }; +} + +function reduce(d, acc, f) { + return Bs_internalAVLtree.reduce(d.data, acc, f); +} + +function every(d, f) { + return Bs_internalAVLtree.every(d.data, f); +} + +function some(d, f) { + return Bs_internalAVLtree.some(d.data, f); +} + +function size(d) { + return Bs_internalAVLtree.size(d.data); +} + +function toList(d) { + return Bs_internalAVLtree.toList(d.data); +} + +function toArray(d) { + return Bs_internalAVLtree.toArray(d.data); +} + +function keysToArray(d) { + return Bs_internalAVLtree.keysToArray(d.data); +} + +function valuesToArray(d) { + return Bs_internalAVLtree.valuesToArray(d.data); +} + +function checkInvariantInternal(d) { + return Bs_internalAVLtree.checkInvariantInternal(d.data); +} + +function has(d, v) { + return Bs_internalMapString.has(d.data, v); +} + +function removeMutateAux(nt, x) { + var k = nt.key; + if (x === k) { + var l = nt.left; + var r = nt.right; + if (l !== null) { + if (r !== null) { + nt.right = Bs_internalAVLtree.removeMinAuxWithRootMutate(nt, r); + return Bs_internalAVLtree.balMutate(nt); + } else { + return l; + } + } else { + return r; + } + } else if (x < k) { + var match = nt.left; + if (match !== null) { + nt.left = removeMutateAux(match, x); + return Bs_internalAVLtree.balMutate(nt); + } else { + return nt; + } + } else { + var match$1 = nt.right; + if (match$1 !== null) { + nt.right = removeMutateAux(match$1, x); + return Bs_internalAVLtree.balMutate(nt); + } else { + return nt; + } + } +} + +function remove(d, v) { + var oldRoot = d.data; + if (oldRoot !== null) { + var newRoot = removeMutateAux(oldRoot, v); + if (newRoot !== oldRoot) { + d.data = newRoot; + return /* () */0; + } else { + return 0; + } + } else { + return /* () */0; + } +} + +function updateDone(t, x, f) { + if (t !== null) { + var k = t.key; + if (k === x) { + var match = f(/* Some */[t.value]); + if (match) { + t.value = match[0]; + return t; + } else { + var l = t.left; + var r = t.right; + if (l !== null) { + if (r !== null) { + t.right = Bs_internalAVLtree.removeMinAuxWithRootMutate(t, r); + return Bs_internalAVLtree.balMutate(t); + } else { + return l; + } + } else { + return r; + } + } + } else { + var l$1 = t.left; + var r$1 = t.right; + if (x < k) { + var ll = updateDone(l$1, x, f); + t.left = ll; + } else { + t.right = updateDone(r$1, x, f); + } + return Bs_internalAVLtree.balMutate(t); + } + } else { + var match$1 = f(/* None */0); + if (match$1) { + return Bs_internalAVLtree.singleton(x, match$1[0]); + } else { + return t; + } + } +} + +function update(t, x, f) { + var oldRoot = t.data; + var newRoot = updateDone(oldRoot, x, f); + if (newRoot !== oldRoot) { + t.data = newRoot; + return /* () */0; + } else { + return 0; + } +} + +function removeArrayMutateAux(_t, xs, _i, len) { + while(true) { + var i = _i; + var t = _t; + if (i < len) { + var ele = xs[i]; + var u = removeMutateAux(t, ele); + if (u !== null) { + _i = i + 1 | 0; + _t = u; + continue ; + + } else { + return Bs_internalAVLtree.empty; + } + } else { + return t; + } + }; +} + +function removeMany(d, xs) { + var oldRoot = d.data; + if (oldRoot !== null) { + var len = xs.length; + var newRoot = removeArrayMutateAux(oldRoot, xs, 0, len); + if (newRoot !== oldRoot) { + d.data = newRoot; + return /* () */0; + } else { + return 0; + } + } else { + return /* () */0; + } +} + +function ofArray(xs) { + return { + data: Bs_internalMapString.ofArray(xs) + }; +} + +function cmp(d0, d1) { + var partial_arg = d1.data; + var partial_arg$1 = d0.data; + return (function (param) { + return Bs_internalMapString.cmp(partial_arg$1, partial_arg, param); + }); +} + +function eq(d0, d1) { + var partial_arg = d1.data; + var partial_arg$1 = d0.data; + return (function (param) { + return Bs_internalMapString.eq(partial_arg$1, partial_arg, param); + }); +} + +function get(d, x) { + return Bs_internalMapString.get(d.data, x); +} + +function getUndefined(d, x) { + return Bs_internalMapString.getUndefined(d.data, x); +} + +function getWithDefault(d, x, def) { + return Bs_internalMapString.getWithDefault(d.data, x, def); +} + +function getExn(d, x) { + return Bs_internalMapString.getExn(d.data, x); +} + +exports.make = make; +exports.clear = clear; +exports.isEmpty = isEmpty; +exports.has = has; +exports.cmp = cmp; +exports.eq = eq; +exports.forEach = forEach; +exports.reduce = reduce; +exports.every = every; +exports.some = some; +exports.size = size; +exports.toList = toList; +exports.toArray = toArray; +exports.ofArray = ofArray; +exports.keysToArray = keysToArray; +exports.valuesToArray = valuesToArray; +exports.minKey = minKey; +exports.minKeyUndefined = minKeyUndefined; +exports.maxKey = maxKey; +exports.maxKeyUndefined = maxKeyUndefined; +exports.minimum = minimum; +exports.minUndefined = minUndefined; +exports.maximum = maximum; +exports.maxUndefined = maxUndefined; +exports.get = get; +exports.getUndefined = getUndefined; +exports.getWithDefault = getWithDefault; +exports.getExn = getExn; +exports.checkInvariantInternal = checkInvariantInternal; +exports.remove = remove; +exports.removeMany = removeMany; +exports.set = set; +exports.update = update; +exports.map = map; +exports.mapWithKey = mapWithKey; +/* No side effect */ diff --git a/lib/js/bs_MutableSet.js b/lib/js/bs_MutableSet.js new file mode 100644 index 0000000000..efad417d82 --- /dev/null +++ b/lib/js/bs_MutableSet.js @@ -0,0 +1,526 @@ +'use strict'; + +var Bs_SortArray = require("./bs_SortArray.js"); +var Bs_internalAVLset = require("./bs_internalAVLset.js"); + +function remove0(nt, x, cmp) { + var k = nt.key; + var c = cmp(x, k); + if (c) { + if (c < 0) { + var match = nt.left; + if (match !== null) { + nt.left = remove0(match, x, cmp); + return Bs_internalAVLset.balMutate(nt); + } else { + return nt; + } + } else { + var match$1 = nt.right; + if (match$1 !== null) { + nt.right = remove0(match$1, x, cmp); + return Bs_internalAVLset.balMutate(nt); + } else { + return nt; + } + } + } else { + var l = nt.left; + var r = nt.right; + if (l !== null) { + if (r !== null) { + nt.right = Bs_internalAVLset.removeMinAuxWithRootMutate(nt, r); + return Bs_internalAVLset.balMutate(nt); + } else { + return l; + } + } else { + return r; + } + } +} + +function remove(d, v) { + var oldRoot = d.data; + if (oldRoot !== null) { + var newRoot = remove0(oldRoot, v, d.cmp); + if (newRoot !== oldRoot) { + d.data = newRoot; + return /* () */0; + } else { + return 0; + } + } else { + return /* () */0; + } +} + +function removeMany0(_t, xs, _i, len, cmp) { + while(true) { + var i = _i; + var t = _t; + if (i < len) { + var ele = xs[i]; + var u = remove0(t, ele, cmp); + if (u !== null) { + _i = i + 1 | 0; + _t = u; + continue ; + + } else { + return Bs_internalAVLset.empty; + } + } else { + return t; + } + }; +} + +function removeMany(d, xs) { + var oldRoot = d.data; + if (oldRoot !== null) { + var len = xs.length; + d.data = removeMany0(oldRoot, xs, 0, len, d.cmp); + return /* () */0; + } else { + return /* () */0; + } +} + +function removeCheck0(nt, x, removed, cmp) { + var k = nt.key; + var c = cmp(x, k); + if (c) { + if (c < 0) { + var match = nt.left; + if (match !== null) { + nt.left = removeCheck0(match, x, removed, cmp); + return Bs_internalAVLset.balMutate(nt); + } else { + return nt; + } + } else { + var match$1 = nt.right; + if (match$1 !== null) { + nt.right = removeCheck0(match$1, x, removed, cmp); + return Bs_internalAVLset.balMutate(nt); + } else { + return nt; + } + } + } else { + removed[0] = /* true */1; + var l = nt.left; + var r = nt.right; + if (l !== null) { + if (r !== null) { + nt.right = Bs_internalAVLset.removeMinAuxWithRootMutate(nt, r); + return Bs_internalAVLset.balMutate(nt); + } else { + return l; + } + } else { + return r; + } + } +} + +function removeCheck(d, v) { + var oldRoot = d.data; + if (oldRoot !== null) { + var removed = [/* false */0]; + var newRoot = removeCheck0(oldRoot, v, removed, d.cmp); + if (newRoot !== oldRoot) { + d.data = newRoot; + } + return removed[0]; + } else { + return /* false */0; + } +} + +function addCheck0(t, x, added, cmp) { + if (t !== null) { + var k = t.key; + var c = cmp(x, k); + if (c) { + var l = t.left; + var r = t.right; + if (c < 0) { + var ll = addCheck0(l, x, added, cmp); + t.left = ll; + } else { + t.right = addCheck0(r, x, added, cmp); + } + return Bs_internalAVLset.balMutate(t); + } else { + return t; + } + } else { + added[0] = /* true */1; + return Bs_internalAVLset.singleton(x); + } +} + +function addCheck(m, e) { + var oldRoot = m.data; + var added = [/* false */0]; + var newRoot = addCheck0(oldRoot, e, added, m.cmp); + if (newRoot !== oldRoot) { + m.data = newRoot; + } + return added[0]; +} + +function add(m, e) { + var oldRoot = m.data; + var newRoot = Bs_internalAVLset.addMutate(m.cmp, oldRoot, e); + if (newRoot !== oldRoot) { + m.data = newRoot; + return /* () */0; + } else { + return 0; + } +} + +function addArrayMutate(t, xs, cmp) { + var v = t; + for(var i = 0 ,i_finish = xs.length - 1 | 0; i <= i_finish; ++i){ + v = Bs_internalAVLset.addMutate(cmp, v, xs[i]); + } + return v; +} + +function mergeMany(d, xs) { + d.data = addArrayMutate(d.data, xs, d.cmp); + return /* () */0; +} + +function make(dict) { + return { + cmp: dict[/* cmp */0], + data: Bs_internalAVLset.empty + }; +} + +function isEmpty(d) { + return Bs_internalAVLset.isEmpty(d.data); +} + +function minimum(d) { + return Bs_internalAVLset.minimum(d.data); +} + +function minUndefined(d) { + return Bs_internalAVLset.minUndefined(d.data); +} + +function maximum(d) { + return Bs_internalAVLset.maximum(d.data); +} + +function maxUndefined(d) { + return Bs_internalAVLset.maxUndefined(d.data); +} + +function forEach(d, f) { + return Bs_internalAVLset.forEach(d.data, f); +} + +function reduce(d, acc, cb) { + return Bs_internalAVLset.reduce(d.data, acc, cb); +} + +function every(d, p) { + return Bs_internalAVLset.every(d.data, p); +} + +function some(d, p) { + return Bs_internalAVLset.some(d.data, p); +} + +function size(d) { + return Bs_internalAVLset.size(d.data); +} + +function toList(d) { + return Bs_internalAVLset.toList(d.data); +} + +function toArray(d) { + return Bs_internalAVLset.toArray(d.data); +} + +function ofSortedArrayUnsafe(xs, dict) { + return { + cmp: dict[/* cmp */0], + data: Bs_internalAVLset.ofSortedArrayUnsafe(xs) + }; +} + +function checkInvariantInternal(d) { + return Bs_internalAVLset.checkInvariantInternal(d.data); +} + +function ofArray(data, dict) { + var cmp = dict[/* cmp */0]; + return { + cmp: cmp, + data: Bs_internalAVLset.ofArray(data, cmp) + }; +} + +function cmp(d0, d1) { + return Bs_internalAVLset.cmp(d0.data, d1.data, d0.cmp); +} + +function eq(d0, d1) { + return Bs_internalAVLset.eq(d0.data, d1.data, d0.cmp); +} + +function get(d, x) { + return Bs_internalAVLset.get(d.data, x, d.cmp); +} + +function getUndefined(d, x) { + return Bs_internalAVLset.getUndefined(d.data, x, d.cmp); +} + +function getExn(d, x) { + return Bs_internalAVLset.getExn(d.data, x, d.cmp); +} + +function split(d, key) { + var arr = Bs_internalAVLset.toArray(d.data); + var cmp = d.cmp; + var i = Bs_SortArray.binarySearchBy(arr, key, cmp); + var len = arr.length; + if (i < 0) { + var next = (-i | 0) - 1 | 0; + return /* tuple */[ + /* tuple */[ + { + cmp: cmp, + data: Bs_internalAVLset.ofSortedArrayAux(arr, 0, next) + }, + { + cmp: cmp, + data: Bs_internalAVLset.ofSortedArrayAux(arr, next, len - next | 0) + } + ], + /* false */0 + ]; + } else { + return /* tuple */[ + /* tuple */[ + { + cmp: cmp, + data: Bs_internalAVLset.ofSortedArrayAux(arr, 0, i) + }, + { + cmp: cmp, + data: Bs_internalAVLset.ofSortedArrayAux(arr, i + 1 | 0, (len - i | 0) - 1 | 0) + } + ], + /* true */1 + ]; + } +} + +function keep(d, p) { + return { + cmp: d.cmp, + data: Bs_internalAVLset.filterCopy(d.data, p) + }; +} + +function partition(d, p) { + var cmp = d.cmp; + var match = Bs_internalAVLset.partitionCopy(d.data, p); + return /* tuple */[ + { + cmp: cmp, + data: match[0] + }, + { + cmp: cmp, + data: match[1] + } + ]; +} + +function subset(a, b) { + return Bs_internalAVLset.subset(a.data, b.data, a.cmp); +} + +function intersect(a, b) { + var cmp = a.cmp; + var match = a.data; + var match$1 = b.data; + if (match !== null) { + if (match$1 !== null) { + var sizea = Bs_internalAVLset.lengthNode(match); + var sizeb = Bs_internalAVLset.lengthNode(match$1); + var totalSize = sizea + sizeb | 0; + var tmp = new Array(totalSize); + Bs_internalAVLset.fillArray(match, 0, tmp); + Bs_internalAVLset.fillArray(match$1, sizea, tmp); + if (cmp(tmp[sizea - 1 | 0], tmp[sizea]) < 0 || cmp(tmp[totalSize - 1 | 0], tmp[0]) < 0) { + return { + cmp: cmp, + data: Bs_internalAVLset.empty + }; + } else { + var tmp2 = new Array(sizea < sizeb ? sizea : sizeb); + var k = Bs_SortArray.intersect(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0, cmp); + return { + cmp: cmp, + data: Bs_internalAVLset.ofSortedArrayAux(tmp2, 0, k) + }; + } + } else { + return { + cmp: cmp, + data: Bs_internalAVLset.empty + }; + } + } else { + return { + cmp: cmp, + data: Bs_internalAVLset.empty + }; + } +} + +function diff(a, b) { + var cmp = a.cmp; + var dataa = a.data; + var match = b.data; + if (dataa !== null) { + if (match !== null) { + var sizea = Bs_internalAVLset.lengthNode(dataa); + var sizeb = Bs_internalAVLset.lengthNode(match); + var totalSize = sizea + sizeb | 0; + var tmp = new Array(totalSize); + Bs_internalAVLset.fillArray(dataa, 0, tmp); + Bs_internalAVLset.fillArray(match, sizea, tmp); + if (cmp(tmp[sizea - 1 | 0], tmp[sizea]) < 0 || cmp(tmp[totalSize - 1 | 0], tmp[0]) < 0) { + return { + cmp: cmp, + data: Bs_internalAVLset.copy(dataa) + }; + } else { + var tmp2 = new Array(sizea); + var k = Bs_SortArray.diff(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0, cmp); + return { + cmp: cmp, + data: Bs_internalAVLset.ofSortedArrayAux(tmp2, 0, k) + }; + } + } else { + return { + cmp: cmp, + data: Bs_internalAVLset.copy(dataa) + }; + } + } else { + return { + cmp: cmp, + data: Bs_internalAVLset.empty + }; + } +} + +function union(a, b) { + var cmp = a.cmp; + var dataa = a.data; + var datab = b.data; + if (dataa !== null) { + if (datab !== null) { + var sizea = Bs_internalAVLset.lengthNode(dataa); + var sizeb = Bs_internalAVLset.lengthNode(datab); + var totalSize = sizea + sizeb | 0; + var tmp = new Array(totalSize); + Bs_internalAVLset.fillArray(dataa, 0, tmp); + Bs_internalAVLset.fillArray(datab, sizea, tmp); + if (cmp(tmp[sizea - 1 | 0], tmp[sizea]) < 0) { + return { + cmp: cmp, + data: Bs_internalAVLset.ofSortedArrayAux(tmp, 0, totalSize) + }; + } else { + var tmp2 = new Array(totalSize); + var k = Bs_SortArray.union(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0, cmp); + return { + cmp: cmp, + data: Bs_internalAVLset.ofSortedArrayAux(tmp2, 0, k) + }; + } + } else { + return { + cmp: cmp, + data: Bs_internalAVLset.copy(dataa) + }; + } + } else { + return { + cmp: cmp, + data: Bs_internalAVLset.copy(datab) + }; + } +} + +function has(d, x) { + return Bs_internalAVLset.has(d.data, x, d.cmp); +} + +function copy(d) { + return { + cmp: d.cmp, + data: Bs_internalAVLset.copy(d.data) + }; +} + +var Int = 0; + +var $$String = 0; + +exports.Int = Int; +exports.$$String = $$String; +exports.make = make; +exports.ofArray = ofArray; +exports.ofSortedArrayUnsafe = ofSortedArrayUnsafe; +exports.copy = copy; +exports.isEmpty = isEmpty; +exports.has = has; +exports.add = add; +exports.addCheck = addCheck; +exports.mergeMany = mergeMany; +exports.remove = remove; +exports.removeCheck = removeCheck; +exports.removeMany = removeMany; +exports.union = union; +exports.intersect = intersect; +exports.diff = diff; +exports.subset = subset; +exports.cmp = cmp; +exports.eq = eq; +exports.forEach = forEach; +exports.reduce = reduce; +exports.every = every; +exports.some = some; +exports.keep = keep; +exports.partition = partition; +exports.size = size; +exports.toList = toList; +exports.toArray = toArray; +exports.minimum = minimum; +exports.minUndefined = minUndefined; +exports.maximum = maximum; +exports.maxUndefined = maxUndefined; +exports.get = get; +exports.getUndefined = getUndefined; +exports.getExn = getExn; +exports.split = split; +exports.checkInvariantInternal = checkInvariantInternal; +/* No side effect */ diff --git a/lib/js/bs_MutableSetInt.js b/lib/js/bs_MutableSetInt.js new file mode 100644 index 0000000000..eb73bb4c0e --- /dev/null +++ b/lib/js/bs_MutableSetInt.js @@ -0,0 +1,502 @@ +'use strict'; + +var Bs_SortArrayInt = require("./bs_SortArrayInt.js"); +var Bs_internalAVLset = require("./bs_internalAVLset.js"); +var Bs_internalSetInt = require("./bs_internalSetInt.js"); + +function remove0(nt, x) { + var k = nt.key; + if (x === k) { + var l = nt.left; + var r = nt.right; + if (l !== null) { + if (r !== null) { + nt.right = Bs_internalAVLset.removeMinAuxWithRootMutate(nt, r); + return Bs_internalAVLset.balMutate(nt); + } else { + return l; + } + } else { + return r; + } + } else if (x < k) { + var match = nt.left; + if (match !== null) { + nt.left = remove0(match, x); + return Bs_internalAVLset.balMutate(nt); + } else { + return nt; + } + } else { + var match$1 = nt.right; + if (match$1 !== null) { + nt.right = remove0(match$1, x); + return Bs_internalAVLset.balMutate(nt); + } else { + return nt; + } + } +} + +function remove(d, v) { + var oldRoot = d.data; + if (oldRoot !== null) { + var newRoot = remove0(oldRoot, v); + if (newRoot !== oldRoot) { + d.data = newRoot; + return /* () */0; + } else { + return 0; + } + } else { + return /* () */0; + } +} + +function removeMany0(_t, xs, _i, len) { + while(true) { + var i = _i; + var t = _t; + if (i < len) { + var ele = xs[i]; + var u = remove0(t, ele); + if (u !== null) { + _i = i + 1 | 0; + _t = u; + continue ; + + } else { + return Bs_internalAVLset.empty; + } + } else { + return t; + } + }; +} + +function removeMany(d, xs) { + var oldRoot = d.data; + if (oldRoot !== null) { + var len = xs.length; + d.data = removeMany0(oldRoot, xs, 0, len); + return /* () */0; + } else { + return /* () */0; + } +} + +function removeCheck0(nt, x, removed) { + var k = nt.key; + if (x === k) { + removed[0] = /* true */1; + var l = nt.left; + var r = nt.right; + if (l !== null) { + if (r !== null) { + nt.right = Bs_internalAVLset.removeMinAuxWithRootMutate(nt, r); + return Bs_internalAVLset.balMutate(nt); + } else { + return l; + } + } else { + return r; + } + } else if (x < k) { + var match = nt.left; + if (match !== null) { + nt.left = removeCheck0(match, x, removed); + return Bs_internalAVLset.balMutate(nt); + } else { + return nt; + } + } else { + var match$1 = nt.right; + if (match$1 !== null) { + nt.right = removeCheck0(match$1, x, removed); + return Bs_internalAVLset.balMutate(nt); + } else { + return nt; + } + } +} + +function removeCheck(d, v) { + var oldRoot = d.data; + if (oldRoot !== null) { + var removed = [/* false */0]; + var newRoot = removeCheck0(oldRoot, v, removed); + if (newRoot !== oldRoot) { + d.data = newRoot; + } + return removed[0]; + } else { + return /* false */0; + } +} + +function addCheck0(t, x, added) { + if (t !== null) { + var k = t.key; + if (x === k) { + return t; + } else { + var l = t.left; + var r = t.right; + if (x < k) { + var ll = addCheck0(l, x, added); + t.left = ll; + } else { + t.right = addCheck0(r, x, added); + } + return Bs_internalAVLset.balMutate(t); + } + } else { + added[0] = /* true */1; + return Bs_internalAVLset.singleton(x); + } +} + +function addCheck(m, e) { + var oldRoot = m.data; + var added = [/* false */0]; + var newRoot = addCheck0(oldRoot, e, added); + if (newRoot !== oldRoot) { + m.data = newRoot; + } + return added[0]; +} + +function add(d, k) { + var oldRoot = d.data; + var v = Bs_internalSetInt.addMutate(oldRoot, k); + if (v !== oldRoot) { + d.data = v; + return /* () */0; + } else { + return 0; + } +} + +function addArrayMutate(t, xs) { + var v = t; + for(var i = 0 ,i_finish = xs.length - 1 | 0; i <= i_finish; ++i){ + v = Bs_internalSetInt.addMutate(v, xs[i]); + } + return v; +} + +function mergeMany(d, arr) { + d.data = addArrayMutate(d.data, arr); + return /* () */0; +} + +function make() { + return { + data: Bs_internalAVLset.empty + }; +} + +function isEmpty(d) { + return Bs_internalAVLset.isEmpty(d.data); +} + +function minimum(d) { + return Bs_internalAVLset.minimum(d.data); +} + +function minUndefined(d) { + return Bs_internalAVLset.minUndefined(d.data); +} + +function maximum(d) { + return Bs_internalAVLset.maximum(d.data); +} + +function maxUndefined(d) { + return Bs_internalAVLset.maxUndefined(d.data); +} + +function forEach(d, f) { + return Bs_internalAVLset.forEach(d.data, f); +} + +function reduce(d, acc, cb) { + return Bs_internalAVLset.reduce(d.data, acc, cb); +} + +function every(d, p) { + return Bs_internalAVLset.every(d.data, p); +} + +function some(d, p) { + return Bs_internalAVLset.some(d.data, p); +} + +function size(d) { + return Bs_internalAVLset.size(d.data); +} + +function toList(d) { + return Bs_internalAVLset.toList(d.data); +} + +function toArray(d) { + return Bs_internalAVLset.toArray(d.data); +} + +function ofSortedArrayUnsafe(xs) { + return { + data: Bs_internalAVLset.ofSortedArrayUnsafe(xs) + }; +} + +function checkInvariantInternal(d) { + return Bs_internalAVLset.checkInvariantInternal(d.data); +} + +function ofArray(xs) { + return { + data: Bs_internalSetInt.ofArray(xs) + }; +} + +function cmp(d0, d1) { + return Bs_internalSetInt.cmp(d0.data, d1.data); +} + +function eq(d0, d1) { + return Bs_internalSetInt.eq(d0.data, d1.data); +} + +function get(d, x) { + return Bs_internalSetInt.get(d.data, x); +} + +function getUndefined(d, x) { + return Bs_internalSetInt.getUndefined(d.data, x); +} + +function getExn(d, x) { + return Bs_internalSetInt.getExn(d.data, x); +} + +function split(d, key) { + var arr = Bs_internalAVLset.toArray(d.data); + var i = Bs_SortArrayInt.binarySearch(arr, key); + var len = arr.length; + if (i < 0) { + var next = (-i | 0) - 1 | 0; + return /* tuple */[ + /* tuple */[ + { + data: Bs_internalAVLset.ofSortedArrayAux(arr, 0, next) + }, + { + data: Bs_internalAVLset.ofSortedArrayAux(arr, next, len - next | 0) + } + ], + /* false */0 + ]; + } else { + return /* tuple */[ + /* tuple */[ + { + data: Bs_internalAVLset.ofSortedArrayAux(arr, 0, i) + }, + { + data: Bs_internalAVLset.ofSortedArrayAux(arr, i + 1 | 0, (len - i | 0) - 1 | 0) + } + ], + /* true */1 + ]; + } +} + +function keep(d, p) { + return { + data: Bs_internalAVLset.filterCopy(d.data, p) + }; +} + +function partition(d, p) { + var match = Bs_internalAVLset.partitionCopy(d.data, p); + return /* tuple */[ + { + data: match[0] + }, + { + data: match[1] + } + ]; +} + +function subset(a, b) { + return Bs_internalSetInt.subset(a.data, b.data); +} + +function intersect(dataa, datab) { + var dataa$1 = dataa.data; + var datab$1 = datab.data; + if (dataa$1 !== null) { + if (datab$1 !== null) { + var sizea = Bs_internalAVLset.lengthNode(dataa$1); + var sizeb = Bs_internalAVLset.lengthNode(datab$1); + var totalSize = sizea + sizeb | 0; + var tmp = new Array(totalSize); + Bs_internalAVLset.fillArray(dataa$1, 0, tmp); + Bs_internalAVLset.fillArray(datab$1, sizea, tmp); + if (tmp[sizea - 1 | 0] < tmp[sizea] || tmp[totalSize - 1 | 0] < tmp[0]) { + return { + data: Bs_internalAVLset.empty + }; + } else { + var tmp2 = new Array(sizea < sizeb ? sizea : sizeb); + var k = Bs_SortArrayInt.intersect(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0); + return { + data: Bs_internalAVLset.ofSortedArrayAux(tmp2, 0, k) + }; + } + } else { + return { + data: Bs_internalAVLset.empty + }; + } + } else { + return { + data: Bs_internalAVLset.empty + }; + } +} + +function diff(dataa, datab) { + var dataa$1 = dataa.data; + var datab$1 = datab.data; + if (dataa$1 !== null) { + if (datab$1 !== null) { + var sizea = Bs_internalAVLset.lengthNode(dataa$1); + var sizeb = Bs_internalAVLset.lengthNode(datab$1); + var totalSize = sizea + sizeb | 0; + var tmp = new Array(totalSize); + Bs_internalAVLset.fillArray(dataa$1, 0, tmp); + Bs_internalAVLset.fillArray(datab$1, sizea, tmp); + if (tmp[sizea - 1 | 0] < tmp[sizea] || tmp[totalSize - 1 | 0] < tmp[0]) { + return { + data: Bs_internalAVLset.copy(dataa$1) + }; + } else { + var tmp2 = new Array(sizea); + var k = Bs_SortArrayInt.diff(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0); + return { + data: Bs_internalAVLset.ofSortedArrayAux(tmp2, 0, k) + }; + } + } else { + return { + data: Bs_internalAVLset.copy(dataa$1) + }; + } + } else { + return { + data: Bs_internalAVLset.empty + }; + } +} + +function union(dataa, datab) { + var dataa$1 = dataa.data; + var datab$1 = datab.data; + if (dataa$1 !== null) { + if (datab$1 !== null) { + var sizea = Bs_internalAVLset.lengthNode(dataa$1); + var sizeb = Bs_internalAVLset.lengthNode(datab$1); + var totalSize = sizea + sizeb | 0; + var tmp = new Array(totalSize); + Bs_internalAVLset.fillArray(dataa$1, 0, tmp); + Bs_internalAVLset.fillArray(datab$1, sizea, tmp); + if (tmp[sizea - 1 | 0] < tmp[sizea]) { + return { + data: Bs_internalAVLset.ofSortedArrayAux(tmp, 0, totalSize) + }; + } else { + var tmp2 = new Array(totalSize); + var k = Bs_SortArrayInt.union(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0); + return { + data: Bs_internalAVLset.ofSortedArrayAux(tmp2, 0, k) + }; + } + } else { + return { + data: Bs_internalAVLset.copy(dataa$1) + }; + } + } else { + return { + data: Bs_internalAVLset.copy(datab$1) + }; + } +} + +function has(d, x) { + return Bs_internalSetInt.has(d.data, x); +} + +function copy(d) { + return { + data: Bs_internalAVLset.copy(d.data) + }; +} + +var I = 0; + +var S = 0; + +var N = 0; + +var A = 0; + +exports.I = I; +exports.S = S; +exports.N = N; +exports.A = A; +exports.remove0 = remove0; +exports.remove = remove; +exports.removeMany0 = removeMany0; +exports.removeMany = removeMany; +exports.removeCheck0 = removeCheck0; +exports.removeCheck = removeCheck; +exports.addCheck0 = addCheck0; +exports.addCheck = addCheck; +exports.add = add; +exports.addArrayMutate = addArrayMutate; +exports.mergeMany = mergeMany; +exports.make = make; +exports.isEmpty = isEmpty; +exports.minimum = minimum; +exports.minUndefined = minUndefined; +exports.maximum = maximum; +exports.maxUndefined = maxUndefined; +exports.forEach = forEach; +exports.reduce = reduce; +exports.every = every; +exports.some = some; +exports.size = size; +exports.toList = toList; +exports.toArray = toArray; +exports.ofSortedArrayUnsafe = ofSortedArrayUnsafe; +exports.checkInvariantInternal = checkInvariantInternal; +exports.ofArray = ofArray; +exports.cmp = cmp; +exports.eq = eq; +exports.get = get; +exports.getUndefined = getUndefined; +exports.getExn = getExn; +exports.split = split; +exports.keep = keep; +exports.partition = partition; +exports.subset = subset; +exports.intersect = intersect; +exports.diff = diff; +exports.union = union; +exports.has = has; +exports.copy = copy; +/* No side effect */ diff --git a/lib/js/bs_MutableSetString.js b/lib/js/bs_MutableSetString.js new file mode 100644 index 0000000000..5cc93a510d --- /dev/null +++ b/lib/js/bs_MutableSetString.js @@ -0,0 +1,485 @@ +'use strict'; + +var Bs_internalAVLset = require("./bs_internalAVLset.js"); +var Bs_SortArrayString = require("./bs_SortArrayString.js"); +var Bs_internalSetString = require("./bs_internalSetString.js"); + +function remove0(nt, x) { + var k = nt.key; + if (x === k) { + var l = nt.left; + var r = nt.right; + if (l !== null) { + if (r !== null) { + nt.right = Bs_internalAVLset.removeMinAuxWithRootMutate(nt, r); + return Bs_internalAVLset.balMutate(nt); + } else { + return l; + } + } else { + return r; + } + } else if (x < k) { + var match = nt.left; + if (match !== null) { + nt.left = remove0(match, x); + return Bs_internalAVLset.balMutate(nt); + } else { + return nt; + } + } else { + var match$1 = nt.right; + if (match$1 !== null) { + nt.right = remove0(match$1, x); + return Bs_internalAVLset.balMutate(nt); + } else { + return nt; + } + } +} + +function remove(d, v) { + var oldRoot = d.data; + if (oldRoot !== null) { + var newRoot = remove0(oldRoot, v); + if (newRoot !== oldRoot) { + d.data = newRoot; + return /* () */0; + } else { + return 0; + } + } else { + return /* () */0; + } +} + +function removeMany0(_t, xs, _i, len) { + while(true) { + var i = _i; + var t = _t; + if (i < len) { + var ele = xs[i]; + var u = remove0(t, ele); + if (u !== null) { + _i = i + 1 | 0; + _t = u; + continue ; + + } else { + return Bs_internalAVLset.empty; + } + } else { + return t; + } + }; +} + +function removeMany(d, xs) { + var oldRoot = d.data; + if (oldRoot !== null) { + var len = xs.length; + d.data = removeMany0(oldRoot, xs, 0, len); + return /* () */0; + } else { + return /* () */0; + } +} + +function removeCheck0(nt, x, removed) { + var k = nt.key; + if (x === k) { + removed[0] = /* true */1; + var l = nt.left; + var r = nt.right; + if (l !== null) { + if (r !== null) { + nt.right = Bs_internalAVLset.removeMinAuxWithRootMutate(nt, r); + return Bs_internalAVLset.balMutate(nt); + } else { + return l; + } + } else { + return r; + } + } else if (x < k) { + var match = nt.left; + if (match !== null) { + nt.left = removeCheck0(match, x, removed); + return Bs_internalAVLset.balMutate(nt); + } else { + return nt; + } + } else { + var match$1 = nt.right; + if (match$1 !== null) { + nt.right = removeCheck0(match$1, x, removed); + return Bs_internalAVLset.balMutate(nt); + } else { + return nt; + } + } +} + +function removeCheck(d, v) { + var oldRoot = d.data; + if (oldRoot !== null) { + var removed = [/* false */0]; + var newRoot = removeCheck0(oldRoot, v, removed); + if (newRoot !== oldRoot) { + d.data = newRoot; + } + return removed[0]; + } else { + return /* false */0; + } +} + +function addCheck0(t, x, added) { + if (t !== null) { + var k = t.key; + if (x === k) { + return t; + } else { + var l = t.left; + var r = t.right; + if (x < k) { + var ll = addCheck0(l, x, added); + t.left = ll; + } else { + t.right = addCheck0(r, x, added); + } + return Bs_internalAVLset.balMutate(t); + } + } else { + added[0] = /* true */1; + return Bs_internalAVLset.singleton(x); + } +} + +function addCheck(m, e) { + var oldRoot = m.data; + var added = [/* false */0]; + var newRoot = addCheck0(oldRoot, e, added); + if (newRoot !== oldRoot) { + m.data = newRoot; + } + return added[0]; +} + +function add(d, k) { + var oldRoot = d.data; + var v = Bs_internalSetString.addMutate(oldRoot, k); + if (v !== oldRoot) { + d.data = v; + return /* () */0; + } else { + return 0; + } +} + +function addArrayMutate(t, xs) { + var v = t; + for(var i = 0 ,i_finish = xs.length - 1 | 0; i <= i_finish; ++i){ + v = Bs_internalSetString.addMutate(v, xs[i]); + } + return v; +} + +function mergeMany(d, arr) { + d.data = addArrayMutate(d.data, arr); + return /* () */0; +} + +function make() { + return { + data: Bs_internalAVLset.empty + }; +} + +function isEmpty(d) { + return Bs_internalAVLset.isEmpty(d.data); +} + +function minimum(d) { + return Bs_internalAVLset.minimum(d.data); +} + +function minUndefined(d) { + return Bs_internalAVLset.minUndefined(d.data); +} + +function maximum(d) { + return Bs_internalAVLset.maximum(d.data); +} + +function maxUndefined(d) { + return Bs_internalAVLset.maxUndefined(d.data); +} + +function forEach(d, f) { + return Bs_internalAVLset.forEach(d.data, f); +} + +function reduce(d, acc, cb) { + return Bs_internalAVLset.reduce(d.data, acc, cb); +} + +function every(d, p) { + return Bs_internalAVLset.every(d.data, p); +} + +function some(d, p) { + return Bs_internalAVLset.some(d.data, p); +} + +function size(d) { + return Bs_internalAVLset.size(d.data); +} + +function toList(d) { + return Bs_internalAVLset.toList(d.data); +} + +function toArray(d) { + return Bs_internalAVLset.toArray(d.data); +} + +function ofSortedArrayUnsafe(xs) { + return { + data: Bs_internalAVLset.ofSortedArrayUnsafe(xs) + }; +} + +function checkInvariantInternal(d) { + return Bs_internalAVLset.checkInvariantInternal(d.data); +} + +function ofArray(xs) { + return { + data: Bs_internalSetString.ofArray(xs) + }; +} + +function cmp(d0, d1) { + return Bs_internalSetString.cmp(d0.data, d1.data); +} + +function eq(d0, d1) { + return Bs_internalSetString.eq(d0.data, d1.data); +} + +function get(d, x) { + return Bs_internalSetString.get(d.data, x); +} + +function getUndefined(d, x) { + return Bs_internalSetString.getUndefined(d.data, x); +} + +function getExn(d, x) { + return Bs_internalSetString.getExn(d.data, x); +} + +function split(d, key) { + var arr = Bs_internalAVLset.toArray(d.data); + var i = Bs_SortArrayString.binarySearch(arr, key); + var len = arr.length; + if (i < 0) { + var next = (-i | 0) - 1 | 0; + return /* tuple */[ + /* tuple */[ + { + data: Bs_internalAVLset.ofSortedArrayAux(arr, 0, next) + }, + { + data: Bs_internalAVLset.ofSortedArrayAux(arr, next, len - next | 0) + } + ], + /* false */0 + ]; + } else { + return /* tuple */[ + /* tuple */[ + { + data: Bs_internalAVLset.ofSortedArrayAux(arr, 0, i) + }, + { + data: Bs_internalAVLset.ofSortedArrayAux(arr, i + 1 | 0, (len - i | 0) - 1 | 0) + } + ], + /* true */1 + ]; + } +} + +function keep(d, p) { + return { + data: Bs_internalAVLset.filterCopy(d.data, p) + }; +} + +function partition(d, p) { + var match = Bs_internalAVLset.partitionCopy(d.data, p); + return /* tuple */[ + { + data: match[0] + }, + { + data: match[1] + } + ]; +} + +function subset(a, b) { + return Bs_internalSetString.subset(a.data, b.data); +} + +function intersect(dataa, datab) { + var dataa$1 = dataa.data; + var datab$1 = datab.data; + if (dataa$1 !== null) { + if (datab$1 !== null) { + var sizea = Bs_internalAVLset.lengthNode(dataa$1); + var sizeb = Bs_internalAVLset.lengthNode(datab$1); + var totalSize = sizea + sizeb | 0; + var tmp = new Array(totalSize); + Bs_internalAVLset.fillArray(dataa$1, 0, tmp); + Bs_internalAVLset.fillArray(datab$1, sizea, tmp); + if (tmp[sizea - 1 | 0] < tmp[sizea] || tmp[totalSize - 1 | 0] < tmp[0]) { + return { + data: Bs_internalAVLset.empty + }; + } else { + var tmp2 = new Array(sizea < sizeb ? sizea : sizeb); + var k = Bs_SortArrayString.intersect(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0); + return { + data: Bs_internalAVLset.ofSortedArrayAux(tmp2, 0, k) + }; + } + } else { + return { + data: Bs_internalAVLset.empty + }; + } + } else { + return { + data: Bs_internalAVLset.empty + }; + } +} + +function diff(dataa, datab) { + var dataa$1 = dataa.data; + var datab$1 = datab.data; + if (dataa$1 !== null) { + if (datab$1 !== null) { + var sizea = Bs_internalAVLset.lengthNode(dataa$1); + var sizeb = Bs_internalAVLset.lengthNode(datab$1); + var totalSize = sizea + sizeb | 0; + var tmp = new Array(totalSize); + Bs_internalAVLset.fillArray(dataa$1, 0, tmp); + Bs_internalAVLset.fillArray(datab$1, sizea, tmp); + if (tmp[sizea - 1 | 0] < tmp[sizea] || tmp[totalSize - 1 | 0] < tmp[0]) { + return { + data: Bs_internalAVLset.copy(dataa$1) + }; + } else { + var tmp2 = new Array(sizea); + var k = Bs_SortArrayString.diff(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0); + return { + data: Bs_internalAVLset.ofSortedArrayAux(tmp2, 0, k) + }; + } + } else { + return { + data: Bs_internalAVLset.copy(dataa$1) + }; + } + } else { + return { + data: Bs_internalAVLset.empty + }; + } +} + +function union(dataa, datab) { + var dataa$1 = dataa.data; + var datab$1 = datab.data; + if (dataa$1 !== null) { + if (datab$1 !== null) { + var sizea = Bs_internalAVLset.lengthNode(dataa$1); + var sizeb = Bs_internalAVLset.lengthNode(datab$1); + var totalSize = sizea + sizeb | 0; + var tmp = new Array(totalSize); + Bs_internalAVLset.fillArray(dataa$1, 0, tmp); + Bs_internalAVLset.fillArray(datab$1, sizea, tmp); + if (tmp[sizea - 1 | 0] < tmp[sizea]) { + return { + data: Bs_internalAVLset.ofSortedArrayAux(tmp, 0, totalSize) + }; + } else { + var tmp2 = new Array(totalSize); + var k = Bs_SortArrayString.union(tmp, 0, sizea, tmp, sizea, sizeb, tmp2, 0); + return { + data: Bs_internalAVLset.ofSortedArrayAux(tmp2, 0, k) + }; + } + } else { + return { + data: Bs_internalAVLset.copy(dataa$1) + }; + } + } else { + return { + data: Bs_internalAVLset.copy(datab$1) + }; + } +} + +function has(d, x) { + return Bs_internalSetString.has(d.data, x); +} + +function copy(d) { + return { + data: Bs_internalAVLset.copy(d.data) + }; +} + +exports.make = make; +exports.ofArray = ofArray; +exports.ofSortedArrayUnsafe = ofSortedArrayUnsafe; +exports.copy = copy; +exports.isEmpty = isEmpty; +exports.has = has; +exports.add = add; +exports.addCheck = addCheck; +exports.mergeMany = mergeMany; +exports.remove = remove; +exports.removeCheck = removeCheck; +exports.removeMany = removeMany; +exports.union = union; +exports.intersect = intersect; +exports.diff = diff; +exports.subset = subset; +exports.cmp = cmp; +exports.eq = eq; +exports.forEach = forEach; +exports.reduce = reduce; +exports.every = every; +exports.some = some; +exports.keep = keep; +exports.partition = partition; +exports.size = size; +exports.toList = toList; +exports.toArray = toArray; +exports.minimum = minimum; +exports.minUndefined = minUndefined; +exports.maximum = maximum; +exports.maxUndefined = maxUndefined; +exports.get = get; +exports.getUndefined = getUndefined; +exports.getExn = getExn; +exports.split = split; +exports.checkInvariantInternal = checkInvariantInternal; +/* No side effect */