Skip to content

Commit

Permalink
Fix hellish range-dirtying bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ProbablyFaiz committed Sep 2, 2022
1 parent 9884bf3 commit 7d64a2e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ func main() {
println(cell.Value.(int))

ss.UpdateCell(cell00.Uuid, `15`)
println(cell.Value.(int))
println(`Cell00 value is now:`, cell00.Value.(int))
println(`Cell value is now:`, cell.Value.(int))

cell03, _ := ss.GetCell("Sheet1", 0, 3)
ss.UpdateCell(cell03.Uuid, `=Min(A1:C4)`)
ss.UpdateCell(cell03.Uuid, `=Sum(A1:C4)`)
println(cell03.Value.(int))
}
4 changes: 2 additions & 2 deletions src/core/computation.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func (cell *Cell) dirty(visited mapset.Set[ReferenceId]) error {
ss.RangeDirtyParents[currRange.Uuid] = mapset.NewThreadUnsafeSet[ReferenceId]()
}
// Tracks the cells that need to be recomputed before recomputing the range.
ss.RangeDirtyParents[cell.Uuid].Add(currRange.Uuid)
ss.RangeDirtyParents[currRange.Uuid].Add(cell.Uuid)
}

// Dirty all dependent cells.
Expand Down Expand Up @@ -152,8 +152,8 @@ func (ss *Spreadsheet) recomputeValues() {
Cell: currCell,
})
currCell.Value, currCell.Error = res, err
currCell.Value = res
}
ss.DirtySet.Clear()
}

func (ss *Spreadsheet) cleanupRanges() {
Expand Down
10 changes: 5 additions & 5 deletions src/core/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,26 +75,26 @@ func (cr *Range) GetUuid() ReferenceId {
}

func (cr *Range) LowAtDimension(dimension uint64) int64 {
if dimension == 0 {
if dimension == 1 {
return int64(cr.StartRow)
} else {
return int64(cr.StartCol)
}
}

func (cr *Range) HighAtDimension(dimension uint64) int64 {
if dimension == 0 {
if dimension == 1 {
return int64(cr.EndRow)
} else {
return int64(cr.EndCol)
}
}

func (cr *Range) OverlapsAtDimension(interval augmentedtree.Interval, dimension uint64) bool {
if dimension == 0 {
return int64(cr.StartRow) <= interval.HighAtDimension(uint64(dimension)) && int64(cr.EndRow) >= interval.LowAtDimension(uint64(dimension))
if dimension == 1 {
return int64(cr.StartRow) <= interval.HighAtDimension(dimension) && int64(cr.EndRow) >= interval.LowAtDimension(dimension)
} else {
return int64(cr.StartCol) <= interval.HighAtDimension(uint64(dimension)) && int64(cr.EndCol) <= interval.LowAtDimension(uint64(dimension))
return int64(cr.StartCol) <= interval.HighAtDimension(dimension) && int64(cr.EndCol) >= interval.LowAtDimension(dimension)
}
}

Expand Down

0 comments on commit 7d64a2e

Please sign in to comment.