// Copyright 2016 by Sascha L. Teichmann // Use of this source code is governed by the MIT license // that can be found in the LICENSE file. package common import ( "bytes" "image" "sync" ) type btPos struct { x int y int } type BaseTileHash struct { // XXX: Maybe use some kind of LRU cache instead? hashes map[btPos][]byte sync.Mutex } func NewBaseTileHash() *BaseTileHash { return &BaseTileHash{hashes: map[btPos][]byte{}} } func (bth *BaseTileHash) Update(x, y int, img image.Image) bool { hash := SHA1Image(img) key := btPos{x, y} bth.Lock() defer bth.Unlock() if old, found := bth.hashes[key]; found { equals := bytes.Equal(old, hash) if !equals { bth.hashes[key] = hash } return !equals } bth.hashes[key] = hash return true }