Skip to content

Commit

Permalink
Merge pull request #3 from isgj/deprecate-size
Browse files Browse the repository at this point in the history
opt: Deprecate Size method
  • Loading branch information
Ismail Gjevori authored May 26, 2022
2 parents 3adf8ea + 145108a commit 27cc180
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
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)
}
}

0 comments on commit 27cc180

Please # to comment.