Skip to content

Commit a58967f

Browse files
author
Dean Karn
authored
Fix list Node Value direct access (#21)
Initial implementation required an extra copy to get the value, fixing to allow direct access.
1 parent 24f8321 commit a58967f

File tree

3 files changed

+104
-109
lines changed

3 files changed

+104
-109
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# pkg
22

3-
![Project status](https://img.shields.io/badge/version-5.12.0-green.svg)
3+
![Project status](https://img.shields.io/badge/version-5.12.1-green.svg)
44
[![Build Status](https://travis-ci.org/go-playground/pkg.svg?branch=master)](https://travis-ci.org/go-playground/pkg)
55
[![Coverage Status](https://coveralls.io/repos/github/go-playground/pkg/badge.svg?branch=master)](https://coveralls.io/github/go-playground/pkg?branch=master)
66
[![GoDoc](https://godoc.org/github.com/go-playground/pkg?status.svg)](https://pkg.go.dev/mod/github.com/go-playground/pkg/v5)

container/list/doubly_linked.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,15 @@ package listext
66
// Node is an element of the doubly linked list.
77
type Node[V any] struct {
88
next, prev *Node[V]
9-
value V
9+
Value V
1010
}
1111

12-
// Value returns the underlying nodes value.
13-
func (n *Node[V]) Value() V {
14-
return n.value
15-
}
16-
17-
// Next returns the nodes next value or nil if it is at the tail.
12+
// Next returns the nodes next Value or nil if it is at the tail.
1813
func (n *Node[V]) Next() *Node[V] {
1914
return n.next
2015
}
2116

22-
// Prev returns the nodes previous value or nil if it is at the head.
17+
// Prev returns the nodes previous Value or nil if it is at the head.
2318
func (n *Node[V]) Prev() *Node[V] {
2419
return n.prev
2520
}
@@ -38,7 +33,7 @@ func NewDoublyLinked[V any]() *DoublyLinkedList[V] {
3833
// PushFront adds an element first in the list.
3934
func (d *DoublyLinkedList[V]) PushFront(v V) *Node[V] {
4035
node := &Node[V]{
41-
value: v,
36+
Value: v,
4237
}
4338
d.pushFront(node)
4439
return d.head
@@ -79,7 +74,7 @@ func (d *DoublyLinkedList[V]) PopFront() *Node[V] {
7974
// PushBack appends an element to the back of a list.
8075
func (d *DoublyLinkedList[V]) PushBack(v V) *Node[V] {
8176
node := &Node[V]{
82-
value: v,
77+
Value: v,
8378
}
8479
d.pushBack(node)
8580
return d.tail
@@ -98,12 +93,12 @@ func (d *DoublyLinkedList[V]) pushBack(node *Node[V]) {
9893
d.len++
9994
}
10095

101-
// PushAfter pushes the supplied value after the supplied node.
96+
// PushAfter pushes the supplied Value after the supplied node.
10297
//
10398
// The supplied node must be attached to the current list otherwise undefined behaviour could occur.
10499
func (d *DoublyLinkedList[V]) PushAfter(node *Node[V], v V) *Node[V] {
105100
newNode := &Node[V]{
106-
value: v,
101+
Value: v,
107102
}
108103
d.MoveAfter(node, newNode)
109104
return newNode
@@ -130,12 +125,12 @@ func (d *DoublyLinkedList[V]) MoveAfter(node *Node[V], moving *Node[V]) {
130125
}
131126
}
132127

133-
// PushBefore pushes the supplied value before the supplied node.
128+
// PushBefore pushes the supplied Value before the supplied node.
134129
//
135130
// The supplied node must be attached to the current list otherwise undefined behaviour could occur.
136131
func (d *DoublyLinkedList[V]) PushBefore(node *Node[V], v V) *Node[V] {
137132
newNode := &Node[V]{
138-
value: v,
133+
Value: v,
139134
}
140135
d.MoveBefore(node, newNode)
141136
return newNode

0 commit comments

Comments
 (0)