mirror of
https://bitbucket.org/s_l_teichmann/mtsatellite
synced 2024-12-24 01:00:18 +01:00
Made size of hashes LRU cache a parameter set by the webmapper.
This commit is contained in:
parent
7cbe2e516c
commit
bae7e7c3e6
@ -24,6 +24,9 @@ import (
|
|||||||
"bitbucket.org/s_l_teichmann/mtsatellite/common"
|
"bitbucket.org/s_l_teichmann/mtsatellite/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Number of check sums to keep in memory.
|
||||||
|
const maxHashedTiles = 256
|
||||||
|
|
||||||
type baseTilesUpdates interface {
|
type baseTilesUpdates interface {
|
||||||
BaseTilesUpdated([]xz)
|
BaseTilesUpdated([]xz)
|
||||||
}
|
}
|
||||||
@ -177,7 +180,7 @@ func activeChanges(changes []xzc) []xz {
|
|||||||
|
|
||||||
func (tu *tileUpdater) doUpdates() {
|
func (tu *tileUpdater) doUpdates() {
|
||||||
|
|
||||||
bth := common.NewBaseTileHash()
|
bth := common.NewBaseTileHash(maxHashedTiles)
|
||||||
|
|
||||||
baseDir := filepath.Join(tu.mapDir, "8")
|
baseDir := filepath.Join(tu.mapDir, "8")
|
||||||
|
|
||||||
|
@ -9,8 +9,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
const btMaxEntries = 256
|
|
||||||
|
|
||||||
type btKey struct {
|
type btKey struct {
|
||||||
x int
|
x int
|
||||||
y int
|
y int
|
||||||
@ -25,13 +23,15 @@ type btHashEntry struct {
|
|||||||
|
|
||||||
type BaseTileHash struct {
|
type BaseTileHash struct {
|
||||||
hashes map[btKey]*btHashEntry
|
hashes map[btKey]*btHashEntry
|
||||||
|
maxEntries int
|
||||||
root btHashEntry
|
root btHashEntry
|
||||||
sync.Mutex
|
sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBaseTileHash() *BaseTileHash {
|
func NewBaseTileHash(maxEntries int) *BaseTileHash {
|
||||||
bth := &BaseTileHash{
|
bth := &BaseTileHash{
|
||||||
hashes: map[btKey]*btHashEntry{}}
|
hashes: map[btKey]*btHashEntry{},
|
||||||
|
maxEntries: maxEntries}
|
||||||
bth.root.next = &bth.root
|
bth.root.next = &bth.root
|
||||||
bth.root.prev = &bth.root
|
bth.root.prev = &bth.root
|
||||||
return bth
|
return bth
|
||||||
@ -76,7 +76,7 @@ func (bth *BaseTileHash) Update(x, y int, hash []byte) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
var entry *btHashEntry
|
var entry *btHashEntry
|
||||||
if len(bth.hashes) >= btMaxEntries {
|
if len(bth.hashes) >= bth.maxEntries {
|
||||||
entry = bth.removeLast()
|
entry = bth.removeLast()
|
||||||
} else {
|
} else {
|
||||||
entry = new(btHashEntry)
|
entry = new(btHashEntry)
|
||||||
|
@ -7,7 +7,7 @@ package common
|
|||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func TestBaseTileHash(t *testing.T) {
|
func TestBaseTileHash(t *testing.T) {
|
||||||
bth := NewBaseTileHash()
|
bth := NewBaseTileHash(256)
|
||||||
h1 := []byte{1}
|
h1 := []byte{1}
|
||||||
h2 := []byte{2}
|
h2 := []byte{2}
|
||||||
for i := 0; i < 600; i++ {
|
for i := 0; i < 600; i++ {
|
||||||
|
Loading…
Reference in New Issue
Block a user