go-bsdiff/internal/native/table_reader.go

38 lines
526 B
Go
Raw Normal View History

2017-02-21 07:26:46 +00:00
package native
import (
"io"
"sync"
)
type readerTable struct {
nextIndex int
table map[int]io.Reader
mutex sync.Mutex
}
func (bt *readerTable) Add(reader io.Reader) (index int) {
bt.mutex.Lock()
defer bt.mutex.Unlock()
if bt.table == nil {
bt.table = map[int]io.Reader{}
}
index = bt.nextIndex
bt.table[index] = reader
// TODO - Handle int overflow
bt.nextIndex++
return
}
func (bt *readerTable) Get(index int) io.Reader {
bt.mutex.Lock()
defer bt.mutex.Unlock()
return bt.table[index]
}