Cosmetical: Replaced a map to bools by a map with struct{} values because its more a set.

This commit is contained in:
Sascha L. Teichmann 2017-02-27 16:12:19 +01:00
parent f437baaac1
commit 3a9fd0ca1e
1 changed files with 5 additions and 6 deletions

View File

@ -23,28 +23,28 @@ type quantizedXZ struct {
}
type changeTracker struct {
changes map[quantizedXZ]bool
changes map[quantizedXZ]struct{}
mutex sync.Mutex
}
func newChangeTracker() *changeTracker {
return &changeTracker{changes: make(map[quantizedXZ]bool)}
return &changeTracker{changes: make(map[quantizedXZ]struct{})}
}
func (ct *changeTracker) BlockChanged(coord common.Coord) {
ct.mutex.Lock()
ct.changes[quantizedXZ{
X: coord.X / quantizationFactor,
Z: coord.Z / quantizationFactor}] = true
Z: coord.Z / quantizationFactor}] = struct{}{}
ct.mutex.Unlock()
}
func (ct *changeTracker) FlushChanges(url string) {
var oldChanges map[quantizedXZ]bool
var oldChanges map[quantizedXZ]struct{}
ct.mutex.Lock()
if len(ct.changes) > 0 {
oldChanges = ct.changes
ct.changes = make(map[quantizedXZ]bool)
ct.changes = make(map[quantizedXZ]struct{})
}
ct.mutex.Unlock()
if oldChanges == nil {
@ -74,5 +74,4 @@ func (ct *changeTracker) FlushChanges(url string) {
log.Printf("WARN: posting changes to %s failed: %s\n", url, err)
}
}()
return
}