-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Segmented list implementation #992
Conversation
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 think we can cut down on the amount of math needed to do a push()
, but that can be a future commit.
std/segmented_list.zig
Outdated
pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type { | ||
return struct { | ||
const Self = this; | ||
const prealloc_base = blk: { |
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.
isn't this more of an exponent than a base?
allocator: &Allocator, | ||
len: usize, | ||
prealloc_segment: [prealloc_item_count]T, | ||
dynamic_segments: []&T, |
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.
After pointer reform, this will be [][*]T
, right?
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.
right
/// Note however that most elements are contiguous, making this data structure cache-friendly. | ||
/// | ||
/// Because it never has to copy elements from an old location to a new location, it does not require | ||
/// its elements to be copyable, and it avoids wasting memory when backed by an ArenaAllocator. |
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.
But push()
and pop()
do require the item be copyable. You might want to say that you can use addOne()
, at()
, and ... shrinkCapacity()
? if you actually want to avoid copying items.
std/segmented_list.zig
Outdated
return struct { | ||
const Self = this; | ||
const prealloc_base = blk: { | ||
assert(prealloc_item_count != 0); |
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 think i understand how this assertion doesn't trip when it actually is 0. because this constant is never used, so the compiler never needs to compute it's value. that definitely needs a comment like "if we get here, then this value is being used" or something.
Related to #986.