From f349497b0185646e4b5afcbdb6244dc8346b9f1a Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Tue, 13 Jun 2023 12:25:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=86=E5=B8=83=E5=9B=BE=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E5=92=8C=E8=8E=B7=E5=8F=96=E5=85=B3=E8=81=94?= =?UTF-8?q?=E6=88=90=E5=91=98=E7=9A=84=E5=87=BD=E6=95=B0=20GetLinks?= =?UTF-8?q?=E3=80=81HasLink?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/g2d/dp/distribution_pattern.go | 18 ++++++++++++++++++ utils/g2d/dp/link.go | 6 ++++++ 2 files changed, 24 insertions(+) create mode 100644 utils/g2d/dp/link.go diff --git a/utils/g2d/dp/distribution_pattern.go b/utils/g2d/dp/distribution_pattern.go index a1acb2d..67ae133 100644 --- a/utils/g2d/dp/distribution_pattern.go +++ b/utils/g2d/dp/distribution_pattern.go @@ -21,6 +21,24 @@ type DistributionPattern[Item any] struct { usePos bool } +// GetLinks 获取关联的成员 +// - 其中包含传入的 pos 成员 +func (slf *DistributionPattern[Item]) GetLinks(pos int) (result []Link[Item]) { + for pos, item := range slf.links[pos] { + result = append(result, Link[Item]{Pos: pos, Item: item}) + } + return +} + +// HasLink 检查一个位置是否包含除它本身外的其他关联成员 +func (slf *DistributionPattern[Item]) HasLink(pos int) bool { + links, exist := slf.links[pos] + if !exist { + return false + } + return len(links) > 1 +} + // LoadMatrix 通过二维矩阵加载分布图 // - 通过该函数加载的分布图使用的矩阵是复制后的矩阵,因此无法直接通过刷新(Refresh)来更新分布关系 // - 需要通过直接刷新的方式请使用 LoadMatrixWithPos diff --git a/utils/g2d/dp/link.go b/utils/g2d/dp/link.go new file mode 100644 index 0000000..54a3040 --- /dev/null +++ b/utils/g2d/dp/link.go @@ -0,0 +1,6 @@ +package dp + +type Link[V any] struct { + Pos int + Item V +}