Skip to content

Commit

Permalink
code reorg
Browse files Browse the repository at this point in the history
  • Loading branch information
bobzhang committed Jan 9, 2018
1 parent 7c72ff1 commit d113baa
Show file tree
Hide file tree
Showing 14 changed files with 298 additions and 284 deletions.
8 changes: 5 additions & 3 deletions jscomp/others/.depend
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ js_mapperRt.cmj : js_mapperRt.cmi
bs_Array.cmj : js_math.cmj bs_Array.cmi
bs_internalAVLset.cmj : bs_Cmp.cmj bs_Array.cmj bs.cmj bs_internalAVLset.cmi
bs_internalAVLtree.cmj : bs_internalAVLtree.cmi
bs_SetIntM.cmj : bs_internalSetInt.cmj bs_internalAVLset.cmj bs_SetIntM.cmi
bs_SetIntM.cmj : bs_internalSetInt.cmj bs_internalAVLset.cmj bs_Array.cmj \
bs_SetIntM.cmi
bs_Hash.cmj : bs_Hash.cmi
bs_Queue.cmj : bs_Array.cmj bs_Queue.cmi
bs_List.cmj : js_json.cmj bs_Array.cmj bs_List.cmi
Expand Down Expand Up @@ -53,11 +54,12 @@ bs_SetM.cmj : bs_internalAVLset.cmj bs_Cmp.cmj bs_BagM.cmj bs_Array.cmj \
bs_internalSetInt.cmj : bs_internalAVLset.cmj bs_Array.cmj
bs_internalSetString.cmj : bs_internalAVLset.cmj bs_Array.cmj
bs_SetInt.cmj : bs_internalSetInt.cmj bs_internalAVLset.cmj bs_SetInt.cmi
bs_SetIntM.cmj : bs_internalSetInt.cmj bs_internalAVLset.cmj bs_SetIntM.cmi
bs_SetIntM.cmj : bs_internalSetInt.cmj bs_internalAVLset.cmj bs_Array.cmj \
bs_SetIntM.cmi
bs_SetString.cmj : bs_internalSetString.cmj bs_internalAVLset.cmj \
bs_SetString.cmi
bs_SetStringM.cmj : bs_internalSetString.cmj bs_internalAVLset.cmj \
bs_SetStringM.cmi
bs_Array.cmj bs_SetStringM.cmi
bs_Stack.cmj : bs_Stack.cmi
node_child_process.cmj : node.cmj
js_boolean.cmj : js_boolean.cmi
Expand Down
1 change: 1 addition & 0 deletions jscomp/others/bs_SetInt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ let inter = I.inter
let union = I.union
let remove = I.remove
let mem = I.mem

58 changes: 53 additions & 5 deletions jscomp/others/bs_SetIntM.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module I = Bs_internalSetInt
# 8
module N = Bs_internalAVLset

module A = Bs_Array

type elt = I.elt

Expand All @@ -11,6 +11,54 @@ type t = {
mutable data : I.t
} [@@bs.deriving abstract]



let rec removeMutateAux nt (x : elt)=
let k = N.key nt in
if x = k then
let l,r = N.(left nt, right nt) in
match N.(toOpt l, toOpt r) with
| Some _, Some nr ->
N.rightSet nt (N.removeMinAuxWithRootMutate nt nr);
N.return (N.balMutate nt)
| None, Some _ ->
r
| (Some _ | None ), None -> l
else
begin
if x < k then
match N.toOpt (N.left nt) with
| None -> N.return nt
| Some l ->
N.leftSet nt (removeMutateAux l x );
N.return (N.balMutate nt)
else
match N.toOpt (N.right nt) with
| None -> N.return nt
| Some r ->
N.rightSet nt (removeMutateAux r x);
N.return (N.balMutate nt)
end

let addArrayMutate t xs =
let v = ref t in
for i = 0 to A.length xs - 1 do
v := I.addMutate !v (A.unsafe_get xs i)
done ;
!v





let removeMutate nt x =
match N.toOpt nt with
| None -> nt
| Some nt -> removeMutateAux nt x




let empty () = t ~data:N.empty0

let isEmpty d =
Expand All @@ -33,7 +81,7 @@ N.maxNull0 (data d)

let iter d f =
N.iter0 (data d) f

let fold d acc cb =
N.fold0 (data d) acc cb
let forAll d p =
Expand Down Expand Up @@ -69,20 +117,20 @@ let add d k =

let addArrayOnly d arr =
let old_data = data d in
let v = I.addArrayMutate old_data arr in
let v = addArrayMutate old_data arr in
if v != old_data then
dataSet d v

let addArray d arr =
let old_data = data d in
let v = I.addArrayMutate old_data arr in
let v = addArrayMutate old_data arr in
if v != old_data then
dataSet d v ;
d

let removeOnly d v =
let old_data = data d in
let v = I.removeMutate old_data v in
let v = removeMutate old_data v in
if v != old_data then
dataSet d v

Expand Down
1 change: 1 addition & 0 deletions jscomp/others/bs_SetString.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ let inter = I.inter
let union = I.union
let remove = I.remove
let mem = I.mem

58 changes: 53 additions & 5 deletions jscomp/others/bs_SetStringM.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module I = Bs_internalSetString
# 8
module N = Bs_internalAVLset

module A = Bs_Array

type elt = I.elt

Expand All @@ -11,6 +11,54 @@ type t = {
mutable data : I.t
} [@@bs.deriving abstract]



let rec removeMutateAux nt (x : elt)=
let k = N.key nt in
if x = k then
let l,r = N.(left nt, right nt) in
match N.(toOpt l, toOpt r) with
| Some _, Some nr ->
N.rightSet nt (N.removeMinAuxWithRootMutate nt nr);
N.return (N.balMutate nt)
| None, Some _ ->
r
| (Some _ | None ), None -> l
else
begin
if x < k then
match N.toOpt (N.left nt) with
| None -> N.return nt
| Some l ->
N.leftSet nt (removeMutateAux l x );
N.return (N.balMutate nt)
else
match N.toOpt (N.right nt) with
| None -> N.return nt
| Some r ->
N.rightSet nt (removeMutateAux r x);
N.return (N.balMutate nt)
end

let addArrayMutate t xs =
let v = ref t in
for i = 0 to A.length xs - 1 do
v := I.addMutate !v (A.unsafe_get xs i)
done ;
!v





let removeMutate nt x =
match N.toOpt nt with
| None -> nt
| Some nt -> removeMutateAux nt x




let empty () = t ~data:N.empty0

let isEmpty d =
Expand All @@ -33,7 +81,7 @@ N.maxNull0 (data d)

let iter d f =
N.iter0 (data d) f

let fold d acc cb =
N.fold0 (data d) acc cb
let forAll d p =
Expand Down Expand Up @@ -69,20 +117,20 @@ let add d k =

let addArrayOnly d arr =
let old_data = data d in
let v = I.addArrayMutate old_data arr in
let v = addArrayMutate old_data arr in
if v != old_data then
dataSet d v

let addArray d arr =
let old_data = data d in
let v = I.addArrayMutate old_data arr in
let v = addArrayMutate old_data arr in
if v != old_data then
dataSet d v ;
d

let removeOnly d v =
let old_data = data d in
let v = I.removeMutate old_data v in
let v = removeMutate old_data v in
if v != old_data then
dataSet d v

Expand Down
57 changes: 7 additions & 50 deletions jscomp/others/bs_internalSetInt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ type elt = int
# 10
module N = Bs_internalAVLset
module A = Bs_Array
type ('elt, 'id) t0 = 'elt N.t0

type t = (elt, unit) t0

type t = elt N.t0

let rec add (t : t) (x : elt) : t =
match N.toOpt t with
Expand Down Expand Up @@ -215,9 +215,8 @@ let rec findNull (n :t) (x : elt) =
if x = v then N.return v
else findNull (if x < v then N.left t else N.right t) x



let rec addMutate (t : _ t0) (x : elt)=
(****************************************************************************)
let rec addMutate t (x : elt)=
match N.toOpt t with
| None -> N.singleton0 x
| Some nt ->
Expand All @@ -232,51 +231,6 @@ let rec addMutate (t : _ t0) (x : elt)=
);
N.return (N.balMutate nt)



let rec removeMutateAux nt (x : elt)=
let k = N.key nt in
if x = k then
let l,r = N.(left nt, right nt) in
match N.(toOpt l, toOpt r) with
| Some _, Some nr ->
N.rightSet nt (N.removeMinAuxWithRootMutate nt nr);
N.return (N.balMutate nt)
| None, Some _ ->
r
| (Some _ | None ), None -> l
else
begin
if x < k then
match N.toOpt (N.left nt) with
| None -> N.return nt
| Some l ->
N.leftSet nt (removeMutateAux l x );
N.return (N.balMutate nt)
else
match N.toOpt (N.right nt) with
| None -> N.return nt
| Some r ->
N.rightSet nt (removeMutateAux r x);
N.return (N.balMutate nt)
end

let removeMutate nt x =
match N.toOpt nt with
| None -> nt
| Some nt -> removeMutateAux nt x




let addArrayMutate (t : _ t0) xs =
let v = ref t in
for i = 0 to A.length xs - 1 do
v := addMutate !v (A.unsafe_get xs i)
done ;
!v


let rec sortedLengthAux (xs : elt array) prec acc len =
if acc >= len then acc
else
Expand All @@ -296,3 +250,6 @@ let ofArray (xs : elt array) =
result := addMutate !result (A.unsafe_get xs i)
done ;
!result



57 changes: 7 additions & 50 deletions jscomp/others/bs_internalSetString.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ type elt = string
# 10
module N = Bs_internalAVLset
module A = Bs_Array
type ('elt, 'id) t0 = 'elt N.t0

type t = (elt, unit) t0

type t = elt N.t0

let rec add (t : t) (x : elt) : t =
match N.toOpt t with
Expand Down Expand Up @@ -215,9 +215,8 @@ let rec findNull (n :t) (x : elt) =
if x = v then N.return v
else findNull (if x < v then N.left t else N.right t) x



let rec addMutate (t : _ t0) (x : elt)=
(****************************************************************************)
let rec addMutate t (x : elt)=
match N.toOpt t with
| None -> N.singleton0 x
| Some nt ->
Expand All @@ -232,51 +231,6 @@ let rec addMutate (t : _ t0) (x : elt)=
);
N.return (N.balMutate nt)



let rec removeMutateAux nt (x : elt)=
let k = N.key nt in
if x = k then
let l,r = N.(left nt, right nt) in
match N.(toOpt l, toOpt r) with
| Some _, Some nr ->
N.rightSet nt (N.removeMinAuxWithRootMutate nt nr);
N.return (N.balMutate nt)
| None, Some _ ->
r
| (Some _ | None ), None -> l
else
begin
if x < k then
match N.toOpt (N.left nt) with
| None -> N.return nt
| Some l ->
N.leftSet nt (removeMutateAux l x );
N.return (N.balMutate nt)
else
match N.toOpt (N.right nt) with
| None -> N.return nt
| Some r ->
N.rightSet nt (removeMutateAux r x);
N.return (N.balMutate nt)
end

let removeMutate nt x =
match N.toOpt nt with
| None -> nt
| Some nt -> removeMutateAux nt x




let addArrayMutate (t : _ t0) xs =
let v = ref t in
for i = 0 to A.length xs - 1 do
v := addMutate !v (A.unsafe_get xs i)
done ;
!v


let rec sortedLengthAux (xs : elt array) prec acc len =
if acc >= len then acc
else
Expand All @@ -296,3 +250,6 @@ let ofArray (xs : elt array) =
result := addMutate !result (A.unsafe_get xs i)
done ;
!result



Loading

0 comments on commit d113baa

Please sign in to comment.