mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-24 01:00:18 +01:00
Simplified tile hash.
This commit is contained in:
parent
0900bd16ce
commit
792aae99d7
@ -10,32 +10,27 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
type btPos struct {
|
|
||||||
x int
|
|
||||||
y int
|
|
||||||
}
|
|
||||||
|
|
||||||
type BaseTileHash struct {
|
type BaseTileHash struct {
|
||||||
// XXX: Maybe use some kind of LRU cache instead?
|
// XXX: Maybe use some kind of LRU cache instead?
|
||||||
hashes map[btPos][]byte
|
hashes map[struct{ x, y int }][]byte
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBaseTileHash() *BaseTileHash {
|
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 {
|
func (bth *BaseTileHash) Update(x, y int, img image.Image) bool {
|
||||||
hash := SHA1Image(img)
|
hash := SHA1Image(img)
|
||||||
key := btPos{x, y}
|
key := struct{ x, y int }{x, y}
|
||||||
bth.Lock()
|
bth.Lock()
|
||||||
defer bth.Unlock()
|
defer bth.Unlock()
|
||||||
if old, found := bth.hashes[key]; found {
|
if old, found := bth.hashes[key]; found {
|
||||||
equals := bytes.Equal(old, hash)
|
if !bytes.Equal(old, hash) {
|
||||||
if !equals {
|
|
||||||
bth.hashes[key] = hash
|
bth.hashes[key] = hash
|
||||||
|
return true
|
||||||
}
|
}
|
||||||
return !equals
|
return false
|
||||||
}
|
}
|
||||||
bth.hashes[key] = hash
|
bth.hashes[key] = hash
|
||||||
return true
|
return true
|
||||||
|
Loading…
Reference in New Issue
Block a user