-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid.go
40 lines (37 loc) · 875 Bytes
/
grid.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package file
// Grid holds the state of the cell grid
type Grid struct {
cells map[int]map[int]*Cell
// Total number of rows and columns
RowTotal int
ColTotal int
// Offset for pagination
RowOff int
ColOff int
// Limit for pagination
RowLim int
ColLim int
}
// GetCell retuns the cell at the position provided
// The cell will be created if it is not present
func (g *Grid) GetCell(row, col int) *Cell {
var cellRow map[int]*Cell
cellRow, ok := g.cells[row]
if !ok {
cellRow = map[int]*Cell{}
g.cells[row] = cellRow
}
var cell *Cell
cell, ok = cellRow[col]
if !ok {
cell = &Cell{Row: row, Col: col}
cellRow[col] = cell
}
return cell
}
// SetCell sets the cell value for the position provided
// The cell will be created if it is not present
func (g *Grid) SetCell(row, col int, value string) {
cell := g.GetCell(row, col)
cell.Value = value
}