clean up node.go
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package models
|
package models
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,15 +24,6 @@ func NewNode() *Node {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) HasTag(tag string) bool {
|
|
||||||
for _, t := range n.Tags {
|
|
||||||
if t == tag {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *Node) AddTag(tag string) {
|
func (n *Node) AddTag(tag string) {
|
||||||
if tag == "" {
|
if tag == "" {
|
||||||
return
|
return
|
||||||
@@ -48,7 +40,7 @@ func (n *Node) AddTag(tag string) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if !n.HasTag(tag) {
|
if !slices.Contains(n.Tags, tag) {
|
||||||
n.Tags = append(n.Tags, tag)
|
n.Tags = append(n.Tags, tag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,15 +55,6 @@ func (n *Node) RemoveTag(tag string) {
|
|||||||
n.Tags = newTags
|
n.Tags = newTags
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *Node) HasRelation(relType RelType, target string) bool {
|
|
||||||
for _, tgt := range n.Relations[string(relType)] {
|
|
||||||
if tgt == target {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *Node) AddRelation(relType RelType, target string) {
|
func (n *Node) AddRelation(relType RelType, target string) {
|
||||||
if n.Relations == nil {
|
if n.Relations == nil {
|
||||||
n.Relations = make(map[string][]string)
|
n.Relations = make(map[string][]string)
|
||||||
@@ -80,7 +63,7 @@ func (n *Node) AddRelation(relType RelType, target string) {
|
|||||||
n.Relations[string(relType)] = []string{target}
|
n.Relations[string(relType)] = []string{target}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !n.HasRelation(relType, target) {
|
if !slices.Contains(n.Relations[string(relType)], target) {
|
||||||
n.Relations[string(relType)] = append(n.Relations[string(relType)], target)
|
n.Relations[string(relType)] = append(n.Relations[string(relType)], target)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user