Skip to content

Commit

Permalink
[ds] Fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
psyomn committed Apr 13, 2021
1 parent 54e2b5a commit 8267e85
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
28 changes: 14 additions & 14 deletions ds/ll.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ var (
ErrEmptyList = errors.New("linked list is empty")
)

type node struct {
next *node
item interface{}
type Node struct {
next *Node
Item interface{}
}

type LinkedList struct {
head *node
head *Node
size uint64
}

Expand All @@ -30,20 +30,20 @@ func (s *LinkedList) Peek() (interface{}, error) {
return nil, ErrEmptyList
}

return s.head.item, nil
return s.head.Item, nil
}

func (s *LinkedList) Add(item interface{}) {
cursor := s.nextEmpty()
if cursor == nil {
s.head = &node{}
s.head.item = item
s.head = &Node{}
s.head.Item = item
} else {
cursor.next = &node{}
cursor.next = &Node{}
cursor = cursor.next
cursor.item = item
cursor.Item = item
}
s.size += 1
s.size++
}

func (s *LinkedList) Delete(item interface{}) error {
Expand All @@ -55,14 +55,14 @@ func (s *LinkedList) Delete(item interface{}) error {
// pray to the garbage collector, ohmmmmm
lag.next = node.next

s.size -= 1
s.size--
return nil
}

func (s *LinkedList) Find(item interface{}) (*node, *node, error) {
func (s *LinkedList) Find(item interface{}) (*Node, *Node, error) {
lag := s.head
for cursor := s.head; cursor != nil; cursor = cursor.next {
if cursor.item == item {
if cursor.Item == item {
return cursor, lag, nil
}
lag = cursor
Expand All @@ -79,7 +79,7 @@ func (s *LinkedList) Length() uint64 {
return s.size
}

func (s *LinkedList) nextEmpty() *node {
func (s *LinkedList) nextEmpty() *Node {
if s.head == nil {
return nil
}
Expand Down
7 changes: 4 additions & 3 deletions ds/ll_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ func TestLinkedListFind(t *testing.T) {
}

if node == nil {
t.Errorf("should have node data")
t.Fatalf("%s", "should have node data")
}

value := node.item.(int)
value := node.Item.(int)
if err != nil {
t.Errorf("%s", err.Error())
}
Expand All @@ -77,9 +77,10 @@ func TestLinkedListFindSmall(t *testing.T) {

if node == nil {
t.Errorf("should have node data")
return
}

value := node.item.(int)
value := node.Item.(int)
if err != nil {
t.Errorf("%s", err.Error())
}
Expand Down

0 comments on commit 8267e85

Please sign in to comment.