mccolljr / segvec

SegVec data structure for rust. Similar to Vec, but allocates memory in chunks of increasing size.
MIT License
33 stars 4 forks source link

Index/Slice improvements #25

Closed cehteh closed 1 year ago

cehteh commented 1 year ago

WIP: just to show what i am working on

The Plan is (what I need here):

(pseudocode)

let segvec = SegVec::new();
fill(segvec);

let slice = segvec.slice(..); 

// planned: subslicing
let subslice = slice[begin..end];

// planned: manual 'Cow', slice to owned:
let new_segvec = SegVec::from(subslice);

Starting bottom up now, extending a 'new_segvec' by Index each element form a slice and push that would be terribly inefficient. So step 1 is the SegmentedIter which walks over (parts of) the segments which can be moved over as whole. Upcoming commits will complete this.

The SegmentedIter is public as well, might be useful in some cases and SegVec doesn't need to hide the fact that it uses segments.

I'll rebase this on master before turning 'draft' into a final PR

cehteh commented 1 year ago

Finished for now. Slice iteration is 64% faster :)

Some things are intentionally left open (I have no need for them now, can be added at some later, perhaps by someone else)

cehteh commented 1 year ago

lol again 1 magic #[inline] makes it blazingly fast, actually its faster than SegVec::iter(&self) -> Iter now. Eventually this might be merged. This would be a breaking change but should simplify the codebase as only one kind of iterators has to be maintained. (can't be done now because DoubleEndedIterator is not implemented for SliceIter)

mccolljr commented 1 year ago

Closing in favor of #26 which includes this work, in addition to further improvements.