formatting for fcore/persistent-vector.sml
This commit is contained in:
@@ -32,10 +32,8 @@ struct
|
||||
else if searchIdx = 0 then
|
||||
isInRange (checkIdx, Vector.sub (nodes, searchIdx))
|
||||
else
|
||||
let
|
||||
val nextCheckIdx = checkIdx - Vector.sub (sizes, searchIdx - 1)
|
||||
in
|
||||
isInRange (nextCheckIdx, Vector.sub (nodes, searchIdx))
|
||||
let val nextCheckIdx = checkIdx - Vector.sub (sizes, searchIdx - 1)
|
||||
in isInRange (nextCheckIdx, Vector.sub (nodes, searchIdx))
|
||||
end
|
||||
end
|
||||
| LEAF (values, sizes) =>
|
||||
@@ -45,10 +43,8 @@ struct
|
||||
if searchIdx = ~1 then
|
||||
false
|
||||
else
|
||||
let
|
||||
val {start, finish} = Vector.sub (values, searchIdx)
|
||||
in
|
||||
checkIdx >= start andalso checkIdx <= finish
|
||||
let val {start, finish} = Vector.sub (values, searchIdx)
|
||||
in checkIdx >= start andalso checkIdx <= finish
|
||||
end
|
||||
end
|
||||
|
||||
@@ -83,8 +79,10 @@ struct
|
||||
let
|
||||
(* adjust "finish" so that it does not consider
|
||||
* offset for "lower" vector *)
|
||||
val finish = finish - Vector.sub (sizes, Vector.length sizes - 1)
|
||||
val newNode = BRANCH (#[newVec], #[finish])
|
||||
val finish =
|
||||
finish - Vector.sub (sizes, Vector.length sizes - 1)
|
||||
val newNode = BRANCH
|
||||
(#[newVec], #[finish])
|
||||
in
|
||||
APPEND newNode
|
||||
end
|
||||
@@ -107,7 +105,10 @@ struct
|
||||
val prevFinish = Vector.sub (sizes, Vector.length sizes - 1)
|
||||
val start = start - prevFinish
|
||||
val finish = finish - prevFinish
|
||||
val newNode = LEAF (#[{start = start, finish = finish}], #[finish])
|
||||
val newNode = LEAF
|
||||
( #[{start = start, finish = finish}]
|
||||
, #[finish]
|
||||
)
|
||||
in
|
||||
APPEND newNode
|
||||
end
|
||||
@@ -128,7 +129,8 @@ struct
|
||||
let
|
||||
val maxSize = getFinishIdx tree
|
||||
in
|
||||
BRANCH (#[tree, newNode], #[maxSize, finish])
|
||||
BRANCH
|
||||
(#[tree, newNode], #[maxSize, finish])
|
||||
end
|
||||
|
||||
fun getStart tree =
|
||||
@@ -142,26 +144,22 @@ struct
|
||||
let
|
||||
val idx = BinSearch.equalOrMore (cursorIdx, sizes)
|
||||
in
|
||||
if idx = ~1 then {start = ~1, finish = ~1}
|
||||
if idx = ~1 then
|
||||
{start = ~1, finish = ~1}
|
||||
else
|
||||
let
|
||||
val {start, finish} = Vector.sub (values, idx)
|
||||
in
|
||||
{start = start + acc, finish = finish + acc}
|
||||
let val {start, finish} = Vector.sub (values, idx)
|
||||
in {start = start + acc, finish = finish + acc}
|
||||
end
|
||||
end
|
||||
| BRANCH (nodes, sizes) =>
|
||||
let
|
||||
val idx = BinSearch.equalOrMore (cursorIdx, sizes)
|
||||
in
|
||||
if idx = ~1 then {start = ~1, finish = ~1}
|
||||
if idx = ~1 then
|
||||
{start = ~1, finish = ~1}
|
||||
else
|
||||
let
|
||||
val prevSize =
|
||||
if idx = 0 then
|
||||
0
|
||||
else
|
||||
Vector.sub (sizes, idx - 1)
|
||||
val prevSize = if idx = 0 then 0 else Vector.sub (sizes, idx - 1)
|
||||
val acc = acc + prevSize
|
||||
val cursorIdx = cursorIdx - prevSize
|
||||
in
|
||||
@@ -185,14 +183,11 @@ struct
|
||||
let
|
||||
val idx = BinSearch.equalOrMore (cursorIdx, sizes)
|
||||
in
|
||||
if idx = ~1 then {start = ~1, finish = ~1}
|
||||
if idx = ~1 then
|
||||
{start = ~1, finish = ~1}
|
||||
else
|
||||
let
|
||||
val prevSize =
|
||||
if idx = 0 then
|
||||
0
|
||||
else
|
||||
Vector.sub (sizes, idx - 1)
|
||||
val prevSize = if idx = 0 then 0 else Vector.sub (sizes, idx - 1)
|
||||
val cursorIdx = cursorIdx - prevSize
|
||||
in
|
||||
helpNextMatch (cursorIdx, Vector.sub (nodes, idx), prevSize)
|
||||
@@ -226,8 +221,7 @@ struct
|
||||
in loopNextMatch (start, finish, tree, count - 1)
|
||||
end
|
||||
else
|
||||
let
|
||||
in
|
||||
let in
|
||||
if cursorIdx >= start andalso cursorIdx <= finish then
|
||||
loopNextMatch (start, finish, tree, count)
|
||||
else
|
||||
@@ -238,10 +232,8 @@ struct
|
||||
fun getLast (tree, acc) =
|
||||
case tree of
|
||||
LEAF (values, _) =>
|
||||
let
|
||||
val {start, finish} = Vector.sub (values, Vector.length values - 1)
|
||||
in
|
||||
{start = start + acc, finish = finish + acc}
|
||||
let val {start, finish} = Vector.sub (values, Vector.length values - 1)
|
||||
in {start = start + acc, finish = finish + acc}
|
||||
end
|
||||
| BRANCH (nodes, sizes) =>
|
||||
let
|
||||
@@ -283,7 +275,8 @@ struct
|
||||
in
|
||||
if #start result < cursorIdx then
|
||||
{start = #start result + acc, finish = #finish result + acc}
|
||||
else {start = ~1, finish = ~1}
|
||||
else
|
||||
{start = ~1, finish = ~1}
|
||||
end
|
||||
else
|
||||
let
|
||||
@@ -307,19 +300,18 @@ struct
|
||||
let
|
||||
val node = Vector.sub (nodes, idx)
|
||||
val prevSize = Vector.sub (sizes, idx - 1)
|
||||
val result = helpPrevMatch (cursorIdx - prevSize, node, acc + prevSize)
|
||||
val result =
|
||||
helpPrevMatch (cursorIdx - prevSize, node, acc + prevSize)
|
||||
in
|
||||
if #start result = ~1 then
|
||||
let
|
||||
val prevPrevSize =
|
||||
if idx - 2 < 0 then
|
||||
0
|
||||
else
|
||||
Vector.sub (sizes, idx - 2)
|
||||
if idx - 2 < 0 then 0 else Vector.sub (sizes, idx - 2)
|
||||
in
|
||||
getLast (Vector.sub (nodes, idx - 1), acc + prevPrevSize)
|
||||
end
|
||||
else result
|
||||
else
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
@@ -358,7 +350,9 @@ struct
|
||||
(* todo: modify below functions so that they also
|
||||
* use rope-like metadata *)
|
||||
|
||||
datatype insert_result = INSERT_UPDATE of t | INSERT_SPLIT of t * t
|
||||
datatype insert_result =
|
||||
INSERT_UPDATE of t
|
||||
| INSERT_SPLIT of t * t
|
||||
|
||||
fun getMaxSize tree =
|
||||
case tree of
|
||||
@@ -444,24 +438,29 @@ struct
|
||||
(* have to split this node too *)
|
||||
let
|
||||
(* slice sizes *)
|
||||
val leftSize = VectorSlice.full #[getMaxSize left]
|
||||
val rightSize = VectorSlice.full #[getMaxSize right]
|
||||
val leftSize =
|
||||
VectorSlice.full #[getMaxSize left]
|
||||
val rightSize =
|
||||
VectorSlice.full #[getMaxSize right]
|
||||
|
||||
val leftLen = SOME idx
|
||||
val rightLen = SOME (Vector.length nodes - idx - 1)
|
||||
|
||||
val leftSizeSlice = VectorSlice.slice (sizes, 0, leftLen)
|
||||
val rightSizeSlice = VectorSlice.slice (sizes, idx + 1, rightLen)
|
||||
val rightSizeSlice =
|
||||
VectorSlice.slice (sizes, idx + 1, rightLen)
|
||||
|
||||
val leftSizes = VectorSlice.concat [leftSizeSlice, leftSize]
|
||||
val rightSizes = VectorSlice.concat [rightSizeSlice, rightSize]
|
||||
val rightSizes =
|
||||
VectorSlice.concat [rightSizeSlice, rightSize]
|
||||
|
||||
(* slice nodes *)
|
||||
val left = VectorSlice.full #[left]
|
||||
val right = VectorSlice.full #[right]
|
||||
|
||||
val leftNodesSlice = VectorSlice.slice (nodes, 0, leftLen)
|
||||
val rightNodesSlice = VectorSlice.slice (nodes, idx + 1, rightLen)
|
||||
val rightNodesSlice =
|
||||
VectorSlice.slice (nodes, idx + 1, rightLen)
|
||||
|
||||
val leftNodes = VectorSlice.concat [leftNodesSlice, left]
|
||||
val rightNodes = VectorSlice.concat [right, rightNodesSlice]
|
||||
@@ -475,7 +474,8 @@ struct
|
||||
else
|
||||
(* can join children into parent *)
|
||||
let
|
||||
val midSizes = #[getMaxSize left, getMaxSize right]
|
||||
val midSizes =
|
||||
#[getMaxSize left, getMaxSize right]
|
||||
val midSizes = VectorSlice.full midSizes
|
||||
val midNodes = #[left, right]
|
||||
val midNodes = VectorSlice.full midNodes
|
||||
@@ -506,8 +506,7 @@ struct
|
||||
in
|
||||
INSERT_UPDATE (LEAF (item, size))
|
||||
end
|
||||
else
|
||||
if finish > Vector.sub (sizes, Vector.length sizes - 1) then
|
||||
else if finish > Vector.sub (sizes, Vector.length sizes - 1) then
|
||||
if Vector.length sizes = maxSize then
|
||||
(* have to split *)
|
||||
let
|
||||
@@ -521,7 +520,8 @@ struct
|
||||
val midItems = VectorSlice.slice (items, halfSize, midLen)
|
||||
|
||||
val rightSizes = VectorSlice.full #[finish]
|
||||
val rightItems = VectorSlice.full #[{start = start, finish = finish}]
|
||||
val rightItems =
|
||||
VectorSlice.full #[{start = start, finish = finish}]
|
||||
|
||||
val rightItems = VectorSlice.concat [midItems, rightItems]
|
||||
val leftItems = VectorSlice.vector leftItems
|
||||
@@ -549,7 +549,8 @@ struct
|
||||
(* have to split *)
|
||||
let
|
||||
val leftSizes = VectorSlice.full #[finish]
|
||||
val leftItems = VectorSlice.full #[{start = start, finish = finish}]
|
||||
val leftItems =
|
||||
VectorSlice.full #[{start = start, finish = finish}]
|
||||
|
||||
val midLen = SOME halfSize
|
||||
val rightLen = SOME (Vector.length items - halfSize)
|
||||
@@ -593,7 +594,8 @@ struct
|
||||
val leftItems = VectorSlice.slice (items, 0, leftLen)
|
||||
val rightItems = VectorSlice.slice (items, idx, rightLen)
|
||||
val midSize = VectorSlice.full #[finish]
|
||||
val midItem = VectorSlice.full #[{start = start, finish = finish}]
|
||||
val midItem =
|
||||
VectorSlice.full #[{start = start, finish = finish}]
|
||||
in
|
||||
if Vector.length items = maxSize then
|
||||
(* have to return split *)
|
||||
|
||||
Reference in New Issue
Block a user