From 27c72db042cd0e7c0844eea12f3f361b924409d0 Mon Sep 17 00:00:00 2001 From: Elias Kohout Date: Wed, 1 Apr 2026 00:39:20 +0200 Subject: [PATCH] clean up node.go --- models/node.go | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/models/node.go b/models/node.go index 00946e0..2bb2631 100644 --- a/models/node.go +++ b/models/node.go @@ -1,6 +1,7 @@ package models import ( + "slices" "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) { if tag == "" { return @@ -48,7 +40,7 @@ func (n *Node) AddTag(tag string) { break } } - if !n.HasTag(tag) { + if !slices.Contains(n.Tags, tag) { n.Tags = append(n.Tags, tag) } } @@ -63,15 +55,6 @@ func (n *Node) RemoveTag(tag string) { 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) { if n.Relations == nil { n.Relations = make(map[string][]string) @@ -80,7 +63,7 @@ func (n *Node) AddRelation(relType RelType, target string) { n.Relations[string(relType)] = []string{target} return } - if !n.HasRelation(relType, target) { + if !slices.Contains(n.Relations[string(relType)], target) { n.Relations[string(relType)] = append(n.Relations[string(relType)], target) } }