From 2ee7091933d2c07338dfb4699ce5665951b47afd Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 16 Mar 2023 18:38:11 -0400 Subject: tree-wide: Ensure that all packages have a doc comment --- lib/containers/doc.go | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 lib/containers/doc.go (limited to 'lib/containers') diff --git a/lib/containers/doc.go b/lib/containers/doc.go new file mode 100644 index 0000000..1725e31 --- /dev/null +++ b/lib/containers/doc.go @@ -0,0 +1,7 @@ +// Copyright (C) 2023 Luke Shumaker +// +// SPDX-License-Identifier: GPL-2.0-or-later + +// Package containers implements generic (type-parameterized) datatype +// containers. +package containers -- cgit v1.2.3-2-g168b From e082cfb3b8f8226067078cc410e4997fd1cf14df Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Thu, 16 Mar 2023 18:45:45 -0400 Subject: tree-wide: Ensure that all existing method doc comments follow the expected format --- lib/containers/ordered.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lib/containers') diff --git a/lib/containers/ordered.go b/lib/containers/ordered.go index 1ebc17e..1289b45 100644 --- a/lib/containers/ordered.go +++ b/lib/containers/ordered.go @@ -12,7 +12,7 @@ type _Ordered[T any] interface { Compare(T) int } -// An Ordered[T] is a type that has a +// An Ordered is a type that has a // // func (a T) Compare(b T) int // @@ -36,10 +36,10 @@ type NativeOrdered[T constraints.Ordered] struct { Val T } -// NativeCompare[T] implements the Ordered[T] Compare operation for +// NativeCompare implements the Ordered[T] Compare operation for // natively-ordered (integer types, float types, and string types). -// While this operation be conceptualized as subtration, -// NativeCompare[T] is careful to avoid integer overflow. +// While this operation be conceptualized as subtration, NativeCompare +// is careful to avoid integer overflow. func NativeCompare[T constraints.Ordered](a, b T) int { switch { case a < b: -- cgit v1.2.3-2-g168b From c30c43f3690931218b88680b337d11a57a2fdc45 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 17 Mar 2023 01:46:40 -0400 Subject: tree-wide: Ensure that all existing type doc comments follow the expected format This is a notable improvement in the docs for btrfsitem. --- lib/containers/linkedlist.go | 2 +- lib/containers/set.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/containers') diff --git a/lib/containers/linkedlist.go b/lib/containers/linkedlist.go index 7d40479..07b4760 100644 --- a/lib/containers/linkedlist.go +++ b/lib/containers/linkedlist.go @@ -8,7 +8,7 @@ import ( "git.lukeshu.com/go/typedsync" ) -// LinkedListEntry[T] is an entry in a LinkedList[T]. +// LinkedListEntry [T] is an entry in a LinkedList [T]. type LinkedListEntry[T any] struct { older, newer *LinkedListEntry[T] Value T diff --git a/lib/containers/set.go b/lib/containers/set.go index 0d9202c..074d126 100644 --- a/lib/containers/set.go +++ b/lib/containers/set.go @@ -14,7 +14,7 @@ import ( "git.lukeshu.com/btrfs-progs-ng/lib/maps" ) -// Set[T] is an unordered set of T. +// Set is an unordered set of T. type Set[T comparable] map[T]struct{} var ( -- cgit v1.2.3-2-g168b From 1ea26f04701fa66e36b058f3efb3a6c7059cdc5c Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 17 Mar 2023 02:28:54 -0400 Subject: tree-wide: Turn on all revive linters (with exceptions) --- lib/containers/intervaltree.go | 2 +- lib/containers/optional.go | 7 +++---- lib/containers/rbtree.go | 3 +-- lib/containers/rbtree_test.go | 30 +++++++++++++++--------------- 4 files changed, 20 insertions(+), 22 deletions(-) (limited to 'lib/containers') diff --git a/lib/containers/intervaltree.go b/lib/containers/intervaltree.go index 7b96526..d2e2732 100644 --- a/lib/containers/intervaltree.go +++ b/lib/containers/intervaltree.go @@ -39,7 +39,7 @@ type IntervalTree[K Ordered[K], V any] struct { inner RBTree[intervalValue[K, V]] } -func (t *IntervalTree[K, V]) attrFn(node *RBNode[intervalValue[K, V]]) { +func (*IntervalTree[K, V]) attrFn(node *RBNode[intervalValue[K, V]]) { max := node.Value.ValSpan.Max if node.Left != nil && node.Left.Value.ChildSpan.Max.Compare(max) > 0 { max = node.Left.Value.ChildSpan.Max diff --git a/lib/containers/optional.go b/lib/containers/optional.go index c0e7b32..5bb7bb6 100644 --- a/lib/containers/optional.go +++ b/lib/containers/optional.go @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Luke Shumaker +// Copyright (C) 2022-2023 Luke Shumaker // // SPDX-License-Identifier: GPL-2.0-or-later @@ -19,11 +19,10 @@ var ( ) func (o Optional[T]) MarshalJSON() ([]byte, error) { - if o.OK { - return json.Marshal(o.Val) - } else { + if !o.OK { return []byte("null"), nil } + return json.Marshal(o.Val) } func (o *Optional[T]) UnmarshalJSON(dat []byte) error { diff --git a/lib/containers/rbtree.go b/lib/containers/rbtree.go index 6182150..59f63aa 100644 --- a/lib/containers/rbtree.go +++ b/lib/containers/rbtree.go @@ -167,9 +167,8 @@ func (t *RBTree[T]) Subrange(rangeFn func(T) int, handleFn func(*RBNode[T]) bool _, node := t.root.search(func(v T) int { if rangeFn(v) <= 0 { return -1 - } else { - return 1 } + return 1 }) for node != nil && rangeFn(node.Value) > 0 { node = node.Next() diff --git a/lib/containers/rbtree_test.go b/lib/containers/rbtree_test.go index d2fe931..c6e7a3b 100644 --- a/lib/containers/rbtree_test.go +++ b/lib/containers/rbtree_test.go @@ -108,25 +108,25 @@ func checkRBTree[T constraints.Ordered](t *testing.T, expectedSet Set[T], tree * } func FuzzRBTree(f *testing.F) { - Ins := uint8(0b0100_0000) - Del := uint8(0) + ins := uint8(0b0100_0000) + del := uint8(0) f.Add([]uint8{}) - f.Add([]uint8{Ins | 5, Del | 5}) - f.Add([]uint8{Ins | 5, Del | 6}) - f.Add([]uint8{Del | 6}) + f.Add([]uint8{ins | 5, del | 5}) + f.Add([]uint8{ins | 5, del | 6}) + f.Add([]uint8{del | 6}) f.Add([]uint8{ // CLRS Figure 14.4 - Ins | 1, - Ins | 2, - Ins | 5, - Ins | 7, - Ins | 8, - Ins | 11, - Ins | 14, - Ins | 15, - - Ins | 4, + ins | 1, + ins | 2, + ins | 5, + ins | 7, + ins | 8, + ins | 11, + ins | 14, + ins | 15, + + ins | 4, }) f.Fuzz(func(t *testing.T, dat []uint8) { -- cgit v1.2.3-2-g168b