Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

opt: Deprecate Size method #3

Merged
merged 1 commit into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestFind(t *testing.T) {
if i != 2 {
t.Errorf("expected 2, got %d", i)
}
i, ok = a.Iter().Find(func(i int) bool { return i == 4 })
_, ok = a.Iter().Find(func(i int) bool { return i == 4 })
if ok {
t.Errorf("expected false, got true")
}
Expand Down
7 changes: 7 additions & 0 deletions linked_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ func (ll *DLList[T]) Iter() Iterator[T] {
}
}

// Len returns the number of elements in the list.
func (ll *DLList[T]) Len() int {
return ll.size
}

// PopBack removes the last element from the list.
// If the second return value is false, the list is empty and the zero value is returned.
func (ll *DLList[T]) PopBack() (T, bool) {
Expand Down Expand Up @@ -140,6 +145,8 @@ func (ll *DLList[T]) ReverseIter() Iterator[T] {
}

// Size returns the number of elements in the list.
//
// Deprecated: Size is deprecated, use Len instead.
func (ll *DLList[T]) Size() int {
return ll.size
}
Expand Down
6 changes: 3 additions & 3 deletions linked_list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,13 @@ func TestPushFront(t *testing.T) {
}
}

func TestSize(t *testing.T) {
func TestLen(t *testing.T) {
var queue DLList[int]
queue.PushBack(1)
queue.PushBack(2)
queue.PushBack(3)
s := queue.Size()
s := queue.Len()
if s != 3 {
t.Errorf("queue.size = %d, want %d", s, 3)
t.Errorf("queue.len = %d, want %d", s, 3)
}
}