Skip to content
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

Merged
merged 3 commits into from
May 7, 2018
Merged

Segmented list implementation #992

merged 3 commits into from
May 7, 2018

Conversation

andrewrk
Copy link
Member

@andrewrk andrewrk commented May 7, 2018

Related to #986.

@andrewrk andrewrk requested a review from thejoshwolfe May 7, 2018 05:06
Copy link
Sponsor Contributor

@thejoshwolfe thejoshwolfe left a 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.

pub fn SegmentedList(comptime T: type, comptime prealloc_item_count: usize) type {
return struct {
const Self = this;
const prealloc_base = blk: {
Copy link
Sponsor Contributor

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,
Copy link
Sponsor Contributor

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?

Copy link
Member Author

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.
Copy link
Sponsor Contributor

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.

return struct {
const Self = this;
const prealloc_base = blk: {
assert(prealloc_item_count != 0);
Copy link
Sponsor Contributor

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.

@andrewrk andrewrk merged commit 78ba3b8 into master May 7, 2018
@andrewrk andrewrk deleted the segmented-list branch May 7, 2018 13:54
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.

None yet

2 participants