aboutsummaryrefslogtreecommitdiff
path: root/src/container
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@golang.org>2018-01-08 16:01:52 +0000
committerBrad Fitzpatrick <bradfitz@golang.org>2018-01-08 18:06:27 +0000
commita99deed39bb945cba922bd312435fdf309b42a13 (patch)
tree45ddbd30bc08567e699e4e2832081bfaee17cf37 /src/container
parenta62071a2092058a5f3d1c47a9841c9f88870e500 (diff)
downloadgo-a99deed39bb945cba922bd312435fdf309b42a13.tar.gz
go-a99deed39bb945cba922bd312435fdf309b42a13.zip
container/list: document nil values more
Fixes #23372 Change-Id: Ie99fb4d84cb49efa66c0ff480d2656c33ef11e6d Reviewed-on: https://go-review.googlesource.com/86676 Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/container')
-rw-r--r--src/container/list/list.go15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/container/list/list.go b/src/container/list/list.go
index 0256768efe..dc4260e131 100644
--- a/src/container/list/list.go
+++ b/src/container/list/list.go
@@ -65,7 +65,7 @@ func New() *List { return new(List).Init() }
// The complexity is O(1).
func (l *List) Len() int { return l.len }
-// Front returns the first element of list l or nil.
+// Front returns the first element of list l or nil if the list is empty.
func (l *List) Front() *Element {
if l.len == 0 {
return nil
@@ -73,7 +73,7 @@ func (l *List) Front() *Element {
return l.root.next
}
-// Back returns the last element of list l or nil.
+// Back returns the last element of list l or nil if the list is empty.
func (l *List) Back() *Element {
if l.len == 0 {
return nil
@@ -118,6 +118,7 @@ func (l *List) remove(e *Element) *Element {
// Remove removes e from l if e is an element of list l.
// It returns the element value e.Value.
+// The element must not be nil.
func (l *List) Remove(e *Element) interface{} {
if e.list == l {
// if e.list == l, l must have been initialized when e was inserted
@@ -141,6 +142,7 @@ func (l *List) PushBack(v interface{}) *Element {
// InsertBefore inserts a new element e with value v immediately before mark and returns e.
// If mark is not an element of l, the list is not modified.
+// The mark must not be nil.
func (l *List) InsertBefore(v interface{}, mark *Element) *Element {
if mark.list != l {
return nil
@@ -151,6 +153,7 @@ func (l *List) InsertBefore(v interface{}, mark *Element) *Element {
// InsertAfter inserts a new element e with value v immediately after mark and returns e.
// If mark is not an element of l, the list is not modified.
+// The mark must not be nil.
func (l *List) InsertAfter(v interface{}, mark *Element) *Element {
if mark.list != l {
return nil
@@ -161,6 +164,7 @@ func (l *List) InsertAfter(v interface{}, mark *Element) *Element {
// MoveToFront moves element e to the front of list l.
// If e is not an element of l, the list is not modified.
+// The element must not be nil.
func (l *List) MoveToFront(e *Element) {
if e.list != l || l.root.next == e {
return
@@ -171,6 +175,7 @@ func (l *List) MoveToFront(e *Element) {
// MoveToBack moves element e to the back of list l.
// If e is not an element of l, the list is not modified.
+// The element must not be nil.
func (l *List) MoveToBack(e *Element) {
if e.list != l || l.root.prev == e {
return
@@ -181,6 +186,7 @@ func (l *List) MoveToBack(e *Element) {
// MoveBefore moves element e to its new position before mark.
// If e or mark is not an element of l, or e == mark, the list is not modified.
+// The element and mark must not be nil.
func (l *List) MoveBefore(e, mark *Element) {
if e.list != l || e == mark || mark.list != l {
return
@@ -190,6 +196,7 @@ func (l *List) MoveBefore(e, mark *Element) {
// MoveAfter moves element e to its new position after mark.
// If e or mark is not an element of l, or e == mark, the list is not modified.
+// The element and mark must not be nil.
func (l *List) MoveAfter(e, mark *Element) {
if e.list != l || e == mark || mark.list != l {
return
@@ -198,7 +205,7 @@ func (l *List) MoveAfter(e, mark *Element) {
}
// PushBackList inserts a copy of an other list at the back of list l.
-// The lists l and other may be the same.
+// The lists l and other may be the same. They must not be nil.
func (l *List) PushBackList(other *List) {
l.lazyInit()
for i, e := other.Len(), other.Front(); i > 0; i, e = i-1, e.Next() {
@@ -207,7 +214,7 @@ func (l *List) PushBackList(other *List) {
}
// PushFrontList inserts a copy of an other list at the front of list l.
-// The lists l and other may be the same.
+// The lists l and other may be the same. They must not be nil.
func (l *List) PushFrontList(other *List) {
l.lazyInit()
for i, e := other.Len(), other.Back(); i > 0; i, e = i-1, e.Prev() {