diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-01-01 19:27:49 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-01-01 22:42:08 -0700 |
commit | c307e7048da3c02e1e540eab227def7fec7340cc (patch) | |
tree | a134fe5f8822e0d9faa7684b6887bc2c139ecd17 /lib/containers | |
parent | 046162cc1ff55985e3dd45eb191729ead1f9cc8d (diff) |
lint: Turn on gocritic
Diffstat (limited to 'lib/containers')
-rw-r--r-- | lib/containers/intervaltree.go | 4 | ||||
-rw-r--r-- | lib/containers/rbtree.go | 7 | ||||
-rw-r--r-- | lib/containers/rbtree_test.go | 10 |
3 files changed, 8 insertions, 13 deletions
diff --git a/lib/containers/intervaltree.go b/lib/containers/intervaltree.go index 424b297..16bc916 100644 --- a/lib/containers/intervaltree.go +++ b/lib/containers/intervaltree.go @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com> +// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com> // // SPDX-License-Identifier: GPL-2.0-or-later @@ -139,4 +139,4 @@ func (t *IntervalTree[K, V]) SearchAll(fn func(K) int) []V { return ret } -//func (t *IntervalTree[K, V]) Walk(fn func(*RBNode[V]) error) error +// TODO: func (t *IntervalTree[K, V]) Walk(fn func(*RBNode[V]) error) error diff --git a/lib/containers/rbtree.go b/lib/containers/rbtree.go index 17bb3e3..f922a7b 100644 --- a/lib/containers/rbtree.go +++ b/lib/containers/rbtree.go @@ -338,11 +338,12 @@ func (t *RBTree[K, V]) Insert(val V) { Parent: parent, Value: val, } - if parent == nil { + switch { + case parent == nil: t.root = node - } else if key.Cmp(t.KeyFn(parent.Value)) < 0 { + case key.Cmp(t.KeyFn(parent.Value)) < 0: parent.Left = node - } else { + default: parent.Right = node } t.updateAttr(node) diff --git a/lib/containers/rbtree_test.go b/lib/containers/rbtree_test.go index a487c52..e42410e 100644 --- a/lib/containers/rbtree_test.go +++ b/lib/containers/rbtree_test.go @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com> +// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com> // // SPDX-License-Identifier: GPL-2.0-or-later @@ -39,13 +39,7 @@ func (node *RBNode[V]) asciiArt(w io.Writer, u, m, l string) { } node.Right.asciiArt(w, u+" ", u+" ,--", u+" | ") - - if node.Color == Red { - fmt.Fprintf(w, "%s%v\n", m, node) - } else { - fmt.Fprintf(w, "%s%v\n", m, node) - } - + fmt.Fprintf(w, "%s%v\n", m, node) node.Left.asciiArt(w, l+" | ", l+" `--", l+" ") } |