done implementing delete function in SearchList
This commit is contained in:
@@ -180,6 +180,9 @@ struct
|
|||||||
in
|
in
|
||||||
if finish > last then
|
if finish > last then
|
||||||
delRightFromHere (finish, left, tl)
|
delRightFromHere (finish, left, tl)
|
||||||
|
else if finish < Vector.sub (hd, 0) then
|
||||||
|
(* finish < first *)
|
||||||
|
{left = left, right = right}
|
||||||
else if finish < last then
|
else if finish < last then
|
||||||
let
|
let
|
||||||
val delpoint = BinSearch.equalOrMore (finish, hd)
|
val delpoint = BinSearch.equalOrMore (finish, hd)
|
||||||
@@ -202,6 +205,9 @@ struct
|
|||||||
in
|
in
|
||||||
if start > last then
|
if start > last then
|
||||||
moveRightAndDelete (start, finish, joinEndOfLeft (hd, left), tl)
|
moveRightAndDelete (start, finish, joinEndOfLeft (hd, left), tl)
|
||||||
|
else if start > Vector.sub (hd, 0) then
|
||||||
|
(* start > first *)
|
||||||
|
{left = left, right = right}
|
||||||
else if start < last then
|
else if start < last then
|
||||||
if finish > last then
|
if finish > last then
|
||||||
(* delete part of hd, and continue deleting rightwards *)
|
(* delete part of hd, and continue deleting rightwards *)
|
||||||
@@ -217,14 +223,16 @@ struct
|
|||||||
let
|
let
|
||||||
val startpoint = BinSearch.equalOrMore (start, hd)
|
val startpoint = BinSearch.equalOrMore (start, hd)
|
||||||
val finishpoint = BinSearch.equalOrMore (finish, hd)
|
val finishpoint = BinSearch.equalOrMore (finish, hd)
|
||||||
val lhd = VectorSlice.slice (hd, 0, SOME (Vector.length hd - startpoint))
|
val lhd = VectorSlice.slice (hd, 0, SOME
|
||||||
|
(Vector.length hd - startpoint))
|
||||||
val rhd = VectorSlice.slice (hd, finishpoint, SOME
|
val rhd = VectorSlice.slice (hd, finishpoint, SOME
|
||||||
(Vector.length hd - finishpoint))
|
(Vector.length hd - finishpoint))
|
||||||
val lhd = VectorSlice.vector lhd
|
val lhd = VectorSlice.vector lhd
|
||||||
val rhd = VectorSlice.vector rhd
|
val rhd = VectorSlice.vector rhd
|
||||||
in
|
in
|
||||||
{ left = joinEndOfLeft (lhd, left), right = joinStartOfRight
|
{ left = joinEndOfLeft (lhd, left)
|
||||||
(rhd, right)}
|
, right = joinStartOfRight (rhd, right)
|
||||||
|
}
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
(* finish = last, which means delete from last part of hd *)
|
(* finish = last, which means delete from last part of hd *)
|
||||||
@@ -245,6 +253,7 @@ struct
|
|||||||
delRightFromHere (finish, joinEndOfLeft (newHd, left), tl)
|
delRightFromHere (finish, joinEndOfLeft (newHd, left), tl)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
| [] => {left = left, right = right}
|
||||||
|
|
||||||
fun delLeftFromHere (start, left, right) =
|
fun delLeftFromHere (start, left, right) =
|
||||||
case left of
|
case left of
|
||||||
@@ -254,6 +263,9 @@ struct
|
|||||||
in
|
in
|
||||||
if start < first then
|
if start < first then
|
||||||
delLeftFromHere (start, tl, right)
|
delLeftFromHere (start, tl, right)
|
||||||
|
else if start > Vector.sub (hd, Vector.length hd - 1) then
|
||||||
|
(* start > last *)
|
||||||
|
{left = left, right = right}
|
||||||
else if start > first then
|
else if start > first then
|
||||||
let
|
let
|
||||||
val delpoint = BinSearch.equalOrMore (start, hd)
|
val delpoint = BinSearch.equalOrMore (start, hd)
|
||||||
@@ -269,6 +281,70 @@ struct
|
|||||||
end
|
end
|
||||||
| [] => {left = left, right = right}
|
| [] => {left = left, right = right}
|
||||||
|
|
||||||
|
fun moveLeftAndDelete (start, finish, left, right) =
|
||||||
|
case left of
|
||||||
|
hd :: tl =>
|
||||||
|
let
|
||||||
|
val first = Vector.sub (hd, 0)
|
||||||
|
in
|
||||||
|
if finish < first then
|
||||||
|
moveLeftAndDelete (start, finish, tl, joinStartOfRight (hd, right))
|
||||||
|
else if finish > Vector.sub (hd, Vector.length hd - 1) then
|
||||||
|
(* finish > last *)
|
||||||
|
{left = left, right = right}
|
||||||
|
else if finish > first then
|
||||||
|
if start < first then
|
||||||
|
(* delete from start of hd and continue deleting leftwards *)
|
||||||
|
let
|
||||||
|
val startpoint = BinSearch.equalOrMore (finish, hd)
|
||||||
|
val len = Vector.length hd - startpoint
|
||||||
|
val newHd = VectorSlice.slice (hd, startpoint, SOME len)
|
||||||
|
val newHd = VectorSlice.vector newHd
|
||||||
|
in
|
||||||
|
delLeftFromHere (start, tl, joinStartOfRight (newHd, right))
|
||||||
|
end
|
||||||
|
else if start > first then
|
||||||
|
(* delete from middle and then return *)
|
||||||
|
let
|
||||||
|
val llen = BinSearch.equalOrMore (start, hd)
|
||||||
|
val rstart = BinSearch.equalOrMore (finish, hd)
|
||||||
|
val rlen = Vector.length hd - rstart
|
||||||
|
val lhd = VectorSlice.slice (hd, 0, SOME llen)
|
||||||
|
val rhd = VectorSlice.slice (hd, rstart, SOME rlen)
|
||||||
|
val lhd = VectorSlice.vector lhd
|
||||||
|
val rhd = VectorSlice.vector rhd
|
||||||
|
in
|
||||||
|
{ left = joinEndOfLeft (lhd, tl)
|
||||||
|
, right = joinStartOfRight (rhd, right)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
else
|
||||||
|
(* start = first and finish > first
|
||||||
|
* have to delete from start of hd and return*)
|
||||||
|
let
|
||||||
|
val startpoint = BinSearch.equalOrMore (finish, hd)
|
||||||
|
val len = Vector.length hd - startpoint
|
||||||
|
val newHd = VectorSlice.slice (hd, startpoint, SOME len)
|
||||||
|
val newHd = VectorSlice.vector newHd
|
||||||
|
in
|
||||||
|
{left = joinEndOfLeft (newHd, tl), right = right}
|
||||||
|
end
|
||||||
|
else
|
||||||
|
(* finish = first *)
|
||||||
|
let
|
||||||
|
val len = Vector.length hd - 1
|
||||||
|
val newHd = VectorSlice.slice (hd, 1, SOME len)
|
||||||
|
val newHd = VectorSlice.vector newHd
|
||||||
|
in
|
||||||
|
if start < first then
|
||||||
|
delLeftFromHere (start, tl, joinStartOfRight (newHd, right))
|
||||||
|
else
|
||||||
|
(* start = first *)
|
||||||
|
{left = tl, right = joinStartOfRight (newHd, right)}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
| [] => {left = left, right = right}
|
||||||
|
|
||||||
fun delFromLeftAndRight (start, finish, left, right) =
|
fun delFromLeftAndRight (start, finish, left, right) =
|
||||||
let val {left, right} = delRightFromHere (finish, left, right)
|
let val {left, right} = delRightFromHere (finish, left, right)
|
||||||
in delLeftFromHere (start, left, right)
|
in delLeftFromHere (start, left, right)
|
||||||
|
|||||||
Reference in New Issue
Block a user