-
Notifications
You must be signed in to change notification settings - Fork 397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(examples): add p/moul/fifo #3736
Conversation
🛠 PR Checks SummaryAll Automated Checks passed. ✅ Manual Checks (for Reviewers):
Read More🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers. ✅ Automated Checks (for Contributors):🟢 Maintainers must be able to edit this pull request (more info) ☑️ Contributor Actions:
☑️ Reviewer Actions:
📚 Resources:Debug
|
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
Signed-off-by: moul <[email protected]>
if l.size < l.maxSize { | ||
l.size++ | ||
} else { | ||
// Remove last element by traversing to second-to-last | ||
if l.size == 1 { | ||
// Special case: if size is 1, just update both pointers | ||
l.head = newNode | ||
l.tail = newNode | ||
newNode.next = nil | ||
} else { | ||
// Find second-to-last node | ||
current := l.head | ||
for current.next != l.tail { | ||
current = current.next | ||
} | ||
current.next = nil | ||
l.tail = current | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: can we avoid this nesting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed and good suggestion @leohhhn. Early returns are very idiomatic Go, so, perhaps please
if l.size < l.maxSize {
l.size++
return
}
// Remove last item by traversing to second-to-last.
if l.size == 1 {
…
return
}
// Find second-to-last node.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: moul <[email protected]>
Signed-off-by: moul [email protected]