From 1faafcd3809fe5b452a1a742137ca2cb7336aad6 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 1 Jan 2023 17:39:11 -0700 Subject: lint: Turn on dupword --- lib/containers/rbtree.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'lib/containers/rbtree.go') diff --git a/lib/containers/rbtree.go b/lib/containers/rbtree.go index e2d8f8a..17bb3e3 100644 --- a/lib/containers/rbtree.go +++ b/lib/containers/rbtree.go @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Luke Shumaker +// Copyright (C) 2022-2023 Luke Shumaker // // SPDX-License-Identifier: GPL-2.0-or-later @@ -65,9 +65,9 @@ func (node *RBNode[V]) walk(fn func(*RBNode[V]) error) error { } // Search the tree for a value that satisfied the given callbackk -// function. A return value of 0 means to to return this value; <0 -// means to go left on the tree (the value is too high), >0 means to -// go right on th etree (the value is too low). +// function. A return value of 0 means to return this value; <0 means +// to go left on the tree (the value is too high), >0 means to go +// right on th etree (the value is too low). // // +-----+ // | v=8 | == 0 : this is it @@ -287,6 +287,8 @@ func (t *RBTree[K, V]) leftRotate(x *RBNode[V]) { } func (t *RBTree[K, V]) rightRotate(y *RBNode[V]) { + //nolint:dupword + // // | | // +---+ +---+ // | y | | x | -- cgit v1.2.3-2-g168b From c307e7048da3c02e1e540eab227def7fec7340cc Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 1 Jan 2023 19:27:49 -0700 Subject: lint: Turn on gocritic --- lib/containers/rbtree.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'lib/containers/rbtree.go') 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) -- cgit v1.2.3-2-g168b From 0c706b6ad52776430ac15cf0e286dd473091d93e Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 1 Jan 2023 21:14:26 -0700 Subject: lint: Turn on predeclared --- lib/containers/rbtree.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/containers/rbtree.go') diff --git a/lib/containers/rbtree.go b/lib/containers/rbtree.go index f922a7b..0430123 100644 --- a/lib/containers/rbtree.go +++ b/lib/containers/rbtree.go @@ -391,10 +391,10 @@ func (t *RBTree[K, V]) Insert(val V) { t.root.Color = Black } -func (t *RBTree[K, V]) transplant(old, new *RBNode[V]) { - *t.parentChild(old) = new - if new != nil { - new.Parent = old.Parent +func (t *RBTree[K, V]) transplant(oldNode, newNode *RBNode[V]) { + *t.parentChild(oldNode) = newNode + if newNode != nil { + newNode.Parent = oldNode.Parent } } -- cgit v1.2.3-2-g168b