summaryrefslogtreecommitdiffhomepage
path: root/pkg/refs
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/refs')
-rwxr-xr-xpkg/refs/weak_ref_list.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/pkg/refs/weak_ref_list.go b/pkg/refs/weak_ref_list.go
index 1d0ae2099..90433fb28 100755
--- a/pkg/refs/weak_ref_list.go
+++ b/pkg/refs/weak_ref_list.go
@@ -52,12 +52,21 @@ func (l *weakRefList) Back() *WeakRef {
return l.tail
}
+// Len returns the number of elements in the list.
+//
+// NOTE: This is an O(n) operation.
+func (l *weakRefList) Len() (count int) {
+ for e := l.Front(); e != nil; e = e.Next() {
+ count++
+ }
+ return count
+}
+
// PushFront inserts the element e at the front of list l.
func (l *weakRefList) PushFront(e *WeakRef) {
linker := weakRefElementMapper{}.linkerFor(e)
linker.SetNext(l.head)
linker.SetPrev(nil)
-
if l.head != nil {
weakRefElementMapper{}.linkerFor(l.head).SetPrev(e)
} else {
@@ -72,7 +81,6 @@ func (l *weakRefList) PushBack(e *WeakRef) {
linker := weakRefElementMapper{}.linkerFor(e)
linker.SetNext(nil)
linker.SetPrev(l.tail)
-
if l.tail != nil {
weakRefElementMapper{}.linkerFor(l.tail).SetNext(e)
} else {
@@ -93,7 +101,6 @@ func (l *weakRefList) PushBackList(m *weakRefList) {
l.tail = m.tail
}
-
m.head = nil
m.tail = nil
}