mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-23 16:50:18 +01:00
Simplified tile hash.
This commit is contained in:
parent
0900bd16ce
commit
792aae99d7
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user