分布图刷新优化

This commit is contained in:
kercylan98 2023-06-13 12:10:24 +08:00
parent f3af67ff66
commit f7a0f294c8
2 changed files with 16 additions and 7 deletions

View File

@ -2,7 +2,6 @@ package dp
import (
"github.com/kercylan98/minotaur/utils/g2d"
"github.com/kercylan98/minotaur/utils/hash"
)
// NewDistributionPattern 构建一个分布图实例
@ -55,12 +54,13 @@ func (slf *DistributionPattern[Item]) Refresh(pos int) {
slf.buildRelationships(pos, slf.matrix[pos])
return
}
temp := hash.Copy(links)
var positions []int
for tp := range links {
positions = append(positions, tp)
delete(slf.links, tp)
}
for tp, target := range temp {
slf.buildRelationships(tp, target)
for _, tp := range positions {
slf.buildRelationships(tp, slf.matrix[tp])
}
}
@ -78,12 +78,13 @@ func (slf *DistributionPattern[Item]) RefreshWithItem(pos int, item Item) {
slf.buildRelationships(pos, slf.matrix[pos])
return
}
temp := hash.Copy(links)
var positions []int
for tp := range links {
positions = append(positions, tp)
delete(slf.links, tp)
}
for tp, target := range temp {
slf.buildRelationships(tp, target)
for _, tp := range positions {
slf.buildRelationships(tp, slf.matrix[tp])
}
}

View File

@ -17,4 +17,12 @@ func TestNewDistributionPattern(t *testing.T) {
for pos, link := range dp.links {
fmt.Println(pos, link, fmt.Sprintf("%p", link))
}
fmt.Println()
matrix[6] = 2
dp.Refresh(6)
for pos, link := range dp.links {
fmt.Println(pos, link, fmt.Sprintf("%p", link))
}
}