-
Notifications
You must be signed in to change notification settings - Fork 382
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/demo/avl/list #3324
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: moul <[email protected]>
🛠 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]>
Signed-off-by: moul <[email protected]>
// l := list.New() | ||
// l.Append(1, 2, 3) | ||
// println(l.Len()) // Output: 3 | ||
func New() *List { |
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.
If the zero value works, then I'd avoid the constructor
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.
// println(l.Range(-1, 2)) // Output: [1 2] | ||
// println(l.Range(3, 999)) // Output: [4 5] | ||
// println(l.Range(3, 2)) // Output: nil | ||
func (l *List) Range(startIndex, endIndex int) []interface{} { |
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.
Slice?
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.
// l.Append(1, 2, 3) | ||
// l.Clear() | ||
// println(l.Len()) // Output: 0 | ||
func (l *List) Clear() { |
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.
Since the zero value is valid, you can do this no?
*l = list.List{}
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.
} | ||
} | ||
|
||
// Clone creates a deep copy of the list. |
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.
This IMO is shallow. (It doesn't attempt to "copy" values contained within)
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.
// // With nil default value | ||
// l2 := list.Make(2, nil) | ||
// println(l2.Get(0)) // Output: nil | ||
func Make(length int, defaultValue interface{}) *List { |
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.
I'm not sure this API makes sense, also because we have no real "benefit" from pre-allocating, and the code to do so is trivial
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]>
Could become the preferred method for managing top-level lists.
It can likely be utilized extensively in the existing codebase, potentially for most instances involving a top-level slice or those involving an avl.Tree using a seqid.