"errors"
)
-type blocks[T any] struct {
+type Blocks[T any] struct {
free chan int
size int
buf []T
var ErrOverflow = errors.New("ErrOverflow")
-func NewBlocks[T any](blockSize int, blockNum int) *blocks[T] {
- p := &blocks[T]{
+func NewBlocks[T any](blockSize int, blockNum int) *Blocks[T] {
+ p := &Blocks[T]{
size: blockSize,
free: make(chan int, blockNum+1),
buf: make([]T, blockSize*blockNum),
// // do something with tmpbuf
// putBack()
// }
-func (t *blocks[T]) Get() ([]T, func(), error) {
+func (t *Blocks[T]) Get() ([]T, func(), error) {
select {
case offset := <-t.free:
offset *= t.size