分布图刷新优化
This commit is contained in:
parent
f3af67ff66
commit
f7a0f294c8
|
@ -2,7 +2,6 @@ package dp
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/kercylan98/minotaur/utils/g2d"
|
"github.com/kercylan98/minotaur/utils/g2d"
|
||||||
"github.com/kercylan98/minotaur/utils/hash"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewDistributionPattern 构建一个分布图实例
|
// NewDistributionPattern 构建一个分布图实例
|
||||||
|
@ -55,12 +54,13 @@ func (slf *DistributionPattern[Item]) Refresh(pos int) {
|
||||||
slf.buildRelationships(pos, slf.matrix[pos])
|
slf.buildRelationships(pos, slf.matrix[pos])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
temp := hash.Copy(links)
|
var positions []int
|
||||||
for tp := range links {
|
for tp := range links {
|
||||||
|
positions = append(positions, tp)
|
||||||
delete(slf.links, tp)
|
delete(slf.links, tp)
|
||||||
}
|
}
|
||||||
for tp, target := range temp {
|
for _, tp := range positions {
|
||||||
slf.buildRelationships(tp, target)
|
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])
|
slf.buildRelationships(pos, slf.matrix[pos])
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
temp := hash.Copy(links)
|
var positions []int
|
||||||
for tp := range links {
|
for tp := range links {
|
||||||
|
positions = append(positions, tp)
|
||||||
delete(slf.links, tp)
|
delete(slf.links, tp)
|
||||||
}
|
}
|
||||||
for tp, target := range temp {
|
for _, tp := range positions {
|
||||||
slf.buildRelationships(tp, target)
|
slf.buildRelationships(tp, slf.matrix[tp])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,4 +17,12 @@ func TestNewDistributionPattern(t *testing.T) {
|
||||||
for pos, link := range dp.links {
|
for pos, link := range dp.links {
|
||||||
fmt.Println(pos, link, fmt.Sprintf("%p", link))
|
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))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue