Skip to content

Commit 5fcfda1

Browse files
committed
add preliminary removeRowRange function
1 parent 589322a commit 5fcfda1

1 file changed

Lines changed: 30 additions & 6 deletions

File tree

src/Core/Table/ArcTableAux.fs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,36 @@ module Unchecked =
603603
else vals.Remove(rowIndex) |> ignore
604604
)
605605
values.RowCount <- values.RowCount - 1
606-
606+
607+
/// Remove cells of one Row, change index of cells with higher index to index - 1
608+
let removeRowRange_withIndexChange (rowStartIndex:int) (rowEndIndex:int) (values:ArcTableValues) =
609+
if rowStartIndex = 0 && values.RowCount = rowEndIndex then
610+
values.RowCount <- 0
611+
values.Columns <- Dictionary()
612+
else
613+
values.Columns
614+
|> Seq.iter (fun kv ->
615+
match kv.Value with
616+
| Constant _ -> ()
617+
| Sparse vals ->
618+
let range = rowEndIndex - rowStartIndex + 1
619+
if rowEndIndex < values.RowCount - 1 then
620+
let col = Dictionary<int, int>()
621+
vals
622+
|> Seq.iter (fun kv ->
623+
let rI = kv.Key
624+
if rI > rowEndIndex then
625+
col.Add(rI - range, kv.Value)
626+
elif rI < rowStartIndex then
627+
col.Add(rI, kv.Value)
628+
)
629+
values.Columns.[kv.Key] <- ColumnValueRefs.Sparse col
630+
else
631+
for rowIndex = rowStartIndex to rowEndIndex do
632+
vals.Remove(rowIndex) |> ignore
633+
)
634+
values.RowCount <- values.RowCount - (rowEndIndex - rowStartIndex + 1)
635+
607636
let moveColumnCellsTo (fromCol:int) (toCol:int) (values:ArcTableValues) =
608637
match IntDictionary.tryFind fromCol values.Columns with
609638
| None -> ()
@@ -660,11 +689,6 @@ module Unchecked =
660689
moveColumnCellsTo (columnIndex) (columnIndex + numberOfNewColumns) values
661690
/// Then we can set the new column at `index`
662691
let setNewCells() =
663-
// Not sure if this is intended? If we for example `forceReplace` a single column table with `Input`and 5 rows with a new column of `Input` ..
664-
// ..and only 2 rows, then table RowCount will decrease from 5 to 2.
665-
// Related Test: `All.ArcTable.addColumn.Existing Table.add less rows, replace input, force replace
666-
//if hasDuplicateUnique.IsSome then
667-
// removeColumnCells(index) values
668692
IntDictionary.addOrUpdate index newCol values.Columns
669693

670694
setNewHeader()

0 commit comments

Comments
 (0)