https://github.com/s0rg/array2d
Generic 2D array
https://github.com/s0rg/array2d
2d-array generic golang
Last synced: about 1 month ago
JSON representation
Generic 2D array
- Host: GitHub
- URL: https://github.com/s0rg/array2d
- Owner: s0rg
- License: mit
- Created: 2022-11-25T14:11:51.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-08-02T19:13:22.000Z (over 2 years ago)
- Last Synced: 2025-01-18T05:31:07.667Z (about 1 year ago)
- Topics: 2d-array, generic, golang
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://pkg.go.dev/github.com/s0rg/array2d)
[](https://github.com/s0rg/array2d/blob/master/LICENSE)
[](go.mod)
[](https://github.com/s0rg/array2d/tags)
[](https://github.com/s0rg/array2d/actions?query=workflow%3Aci)
[](https://goreportcard.com/report/github.com/s0rg/array2d)
[](https://qlty.sh/gh/s0rg/projects/array2d)
[](https://qlty.sh/gh/s0rg/projects/array2d)

# array2d
Generic 2D array
# features
- zero-alloc
- 100% test coverage
# example
```go
import (
"fmt"
"github.com/s0rg/array2d"
)
func main() {
// create new 2D array with given type and dimensions (width x height)
a := array2d.New[int](15, 20)
// fill with ones
a.Fill(func() (value int) {
return 1
})
// set value at given coords
a.Set(1, 2, 100)
// get values
t1, ok := a.Get(1, 1)
if !ok {
panic("nothing at 1x1")
}
t2, ok := a.Get(1, 2)
if !ok {
panic("nothing at 1x2")
}
fmt.Println(t1, t2) // should print: 1, 100
}
```
# benchmarks
```
goos: linux
goarch: amd64
pkg: github.com/s0rg/array2d
cpu: AMD Ryzen 5 5500U with Radeon Graphics
BenchmarkArray/Set-12 1000000000 1.002 ns/op 0 B/op 0 allocs/op
BenchmarkArray/Get-12 927178446 1.250 ns/op 0 B/op 0 allocs/op
BenchmarkArray/Iter-12 39491674 30.68 ns/op 0 B/op 0 allocs/op
BenchmarkArray/Fill-12 20840200 56.84 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/s0rg/array2d 4.897s
```