go-bsdiff/internal/native/table_writer.go

38 lines
526 B
Go
Raw Normal View History

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