Simplified tile hash.

This commit is contained in:
Sascha L. Teichmann 2016-05-08 17:22:04 +02:00
parent 0900bd16ce
commit 792aae99d7
1 changed files with 6 additions and 11 deletions

View File

@ -10,32 +10,27 @@ import (
"sync"
)
type btPos struct {
x int
y int
}
type BaseTileHash struct {
// XXX: Maybe use some kind of LRU cache instead?
hashes map[btPos][]byte
hashes map[struct{ x, y int }][]byte
sync.Mutex
}
func NewBaseTileHash() *BaseTileHash {
return &BaseTileHash{hashes: map[btPos][]byte{}}
return &BaseTileHash{hashes: map[struct{ x, y int }][]byte{}}
}
func (bth *BaseTileHash) Update(x, y int, img image.Image) bool {
hash := SHA1Image(img)
key := btPos{x, y}
key := struct{ x, y int }{x, y}
bth.Lock()
defer bth.Unlock()
if old, found := bth.hashes[key]; found {
equals := bytes.Equal(old, hash)
if !equals {
if !bytes.Equal(old, hash) {
bth.hashes[key] = hash
return true
}
return !equals
return false
}
bth.hashes[key] = hash
return true