fix part slices were no pinters
This commit is contained in:
+31
-17
@@ -25,27 +25,38 @@ type Field struct {
|
||||
// GETTER //
|
||||
// ────────────────────────────────────────────────────────────────────────────── //
|
||||
|
||||
func (f *Field) GetRow(r int) (*Line, error) {
|
||||
func (f *Field) GetRow(r int) (*Row, error) {
|
||||
if r >= f.rows || r < 0 {
|
||||
return nil, outOfBound
|
||||
}
|
||||
|
||||
return &Line{cells: append([]Cell(nil), f.cells[r]...)}, nil
|
||||
cellPtrs := make([]*Cell, len(f.cells[r]))
|
||||
for i := range f.cells[r] {
|
||||
cellPtrs[i] = &f.cells[r][i]
|
||||
}
|
||||
|
||||
return &Row{
|
||||
Line: Line{
|
||||
cells: cellPtrs,
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (f *Field) GetColumn(c int) (*Line, error) {
|
||||
func (f *Field) GetColumn(c int) (*Column, error) {
|
||||
if c >= f.columns || c < 0 {
|
||||
return nil, outOfBound
|
||||
}
|
||||
|
||||
// Performance
|
||||
result := &Line{
|
||||
cells: make([]Cell, 0, f.rows),
|
||||
result := &Column{
|
||||
Line: Line{
|
||||
cells: make([]*Cell, 0, f.rows),
|
||||
},
|
||||
}
|
||||
|
||||
// Copying
|
||||
for _, row := range f.cells {
|
||||
result.cells = append(result.cells, row[c])
|
||||
result.cells = append(result.cells, &row[c])
|
||||
}
|
||||
|
||||
return result, nil
|
||||
@@ -60,13 +71,16 @@ func (f *Field) GetBlock(r, c int) (*Block, error) {
|
||||
startCol := c * f.blockSizeColumn
|
||||
|
||||
block := &Block{
|
||||
cells: make([][]Cell, f.blockSizeRow),
|
||||
cells: make([][]*Cell, f.blockSizeRow),
|
||||
}
|
||||
|
||||
for row := range block.cells {
|
||||
// Effizientes Kopieren der Zeile
|
||||
block.cells[row] = make([]Cell, f.blockSizeColumn)
|
||||
copy(block.cells[row], f.cells[startRow+row][startCol:startCol+f.blockSizeColumn])
|
||||
block.cells[row] = make([]*Cell, f.blockSizeColumn)
|
||||
|
||||
for column := range block.cells[row] {
|
||||
block.cells[row][column] = &f.cells[startRow+row][startCol+column]
|
||||
}
|
||||
}
|
||||
|
||||
return block, nil
|
||||
@@ -84,12 +98,12 @@ func (f *Field) GetCell(r, c int) (*Cell, error) {
|
||||
// ────────────────────────────────────────────────────────────────────────────── //
|
||||
|
||||
func (f *Field) ForEachPart(fn func(part Part)) {
|
||||
f.ForEachRow(func(line *Line) {
|
||||
fn(line)
|
||||
f.ForEachRow(func(row *Row) {
|
||||
fn(row)
|
||||
})
|
||||
|
||||
f.ForEachColumn(func(line *Line) {
|
||||
fn(line)
|
||||
f.ForEachColumn(func(column *Column) {
|
||||
fn(column)
|
||||
})
|
||||
|
||||
f.ForEachBlock(func(block *Block) {
|
||||
@@ -97,18 +111,18 @@ func (f *Field) ForEachPart(fn func(part Part)) {
|
||||
})
|
||||
}
|
||||
|
||||
func (f *Field) ForEachRow(fn func(line *Line)) {
|
||||
func (f *Field) ForEachRow(fn func(row *Row)) {
|
||||
for i := range f.rows {
|
||||
line, err := f.GetRow(i)
|
||||
row, err := f.GetRow(i)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
fn(line)
|
||||
fn(row)
|
||||
}
|
||||
}
|
||||
|
||||
func (f *Field) ForEachColumn(fn func(line *Line)) {
|
||||
func (f *Field) ForEachColumn(fn func(column *Column)) {
|
||||
for i := range f.columns {
|
||||
column, err := f.GetColumn(i)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user