Skip to content

Feat: Understanding data structure#1

Open
glennsteven wants to merge 11 commits into
josestg:mainfrom
glennsteven:glnsteven/ds
Open

Feat: Understanding data structure#1
glennsteven wants to merge 11 commits into
josestg:mainfrom
glennsteven:glnsteven/ds

Conversation

@glennsteven

Copy link
Copy Markdown

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request implements TODO functions across multiple data structure packages, converting placeholder panic statements into working implementations. The PR covers fundamental operations for stacks, queues, sets, linked lists (singly, doubly, and circular doubly), hashmaps, and dynamic arrays.

Changes:

  • Implemented core data structure methods (Empty, Size, Push/Pop, Enqueue/Dequeue, Add/Del, Append/Prepend, etc.)
  • Added iterator functions for various traversal patterns
  • Implemented set operations (Union, Intersection, Disjoint)
  • Added a redundant t.Helper() call in test utility

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
stack/stack.go Implemented stack operations: Empty, Size, TryPeek, Push, TryPop, String, Iter, and backend initialization
queue/queue.go Implemented queue operations: Empty, Size, TryPeek, Enqueue, TryDequeue, String, Iter, and backend initialization
sets/hashset.go Implemented set operations: Add, Del, Exists, String, Iter, Union, Intersection, and Disjoint
linkedlist/singly_linkedlist.go Implemented singly linked list operations: Append, Prepend, TryPop, TryShift, iterators, TryGet, TrySet, TryRemove, and Insert
linkedlist/doubly_linkedlist.go Implemented doubly linked list operations: Prepend, Append, TryPop, TryShift, iterators, TryGet, TrySet, Insert, and TryRemove
linkedlist/circular_doubly_linkedlist.go Implemented circular doubly linked list operations: Append, Prepend, TryPop, TryShift, TryGet, TrySet, Insert, TryRemove, and iterators
hashmap/hashmap_chaining.go Implemented hashmap operations: Put, Del, internal put, Iter, Keys, Get, String, bucketIndex, and growAndRehash
dynamicarray/dynamicarray.go Implemented dynamic array operations: Size, Cap, TryTail, Prepend, TryShift, Append, IterBackward, EnumBackward, TryRemove, plus formatting fixes
adt/prop/prop.go Added redundant t.Helper() call in mustPanic test utility

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


l.checkBounds(index)
curr := l.nodeAt(index)
n := NewBinaryNode(data, curr, curr.next)

Copilot AI Feb 13, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect node creation: The second parameter should be curr.prev, not curr.next. According to the hint, the new node should have next=curr and prev=curr.prev. Currently, this creates a node with both next and prev pointing in the wrong direction for insertion.

Suggested change
n := NewBinaryNode(data, curr, curr.next)
n := NewBinaryNode(data, curr, curr.prev)

Copilot uses AI. Check for mistakes.
Comment thread queue/queue.go
// 3) return (q.b.Head(), true) - front of queue is head
panic("todo: please implement me!")
q.ensureBackend()
if q.Empty() {

Copilot AI Feb 13, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inefficient: This calls q.Empty() which internally calls ensureBackend() again, resulting in redundant invocation. Should use q.b.Empty() instead to check the backend directly, following the same pattern as the stack implementation.

Suggested change
if q.Empty() {
if q.b.Empty() {

Copilot uses AI. Check for mistakes.
Comment thread queue/queue.go
// 3) return (q.b.Shift(), true) - dequeue from front = shift from head
panic("todo: please implement me!")
q.ensureBackend()
if q.Empty() {

Copilot AI Feb 13, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inefficient: This calls q.Empty() which internally calls ensureBackend() again, resulting in redundant invocation. Should use q.b.Empty() instead to check the backend directly, following the same pattern as the stack implementation.

Suggested change
if q.Empty() {
if q.b.Empty() {

Copilot uses AI. Check for mistakes.
}
d.backend.Set(index, value)
return true
if d.Empty() || index < 0 || index >= d.Size() {

Copilot AI Feb 13, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant check: The d.Empty() condition is unnecessary because when the array is empty, d.Size() returns 0, and any valid index check index >= d.Size() will already handle that case. This is inconsistent with TryGet which only checks the index bounds.

Suggested change
if d.Empty() || index < 0 || index >= d.Size() {
if index < 0 || index >= d.Size() {

Copilot uses AI. Check for mistakes.
Comment thread adt/prop/prop.go
t.Helper()
defer func() {
if recover() == nil {
t.Helper()

Copilot AI Feb 13, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant: The t.Helper() call here is unnecessary. The function already calls t.Helper() on line 1460, which marks mustPanic as a test helper. Calling it again inside the deferred function doesn't provide additional value and is unusual Go testing practice.

Suggested change
t.Helper()

Copilot uses AI. Check for mistakes.
}
h.size = nw.Size()
h.buckets = nw.buckets
nw = nil

Copilot AI Feb 13, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary assignment: Setting nw = nil is redundant since the variable goes out of scope immediately after this line. Go's garbage collector will handle the cleanup automatically once there are no more references to the old hashmap.

Suggested change
nw = nil

Copilot uses AI. Check for mistakes.
Comment on lines +286 to +290
l.head = n
} else {
n.next = l.head
l.head = n
}

Copilot AI Feb 13, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant assignment: n.next is already set to l.head during node creation on line 283 using NewUnaryNode(data, l.head). This line unnecessarily sets it again.

Suggested change
l.head = n
} else {
n.next = l.head
l.head = n
}
}
l.head = n

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants