Expand description
This crate provides the SegVec data structure.
It is similar to Vec, but allocates memory in chunks, referred to as
“segments”. This involves a few trade-offs:
§Pros:
- Element addresses are stable across
pushoperations even if theSegVecmust grow. - Resizing only allocates the additional space needed, and doesn’t require copying.
§Cons:
- Operations are slower (some, like
insert,remove, anddrain, are much slower) than for aVecdue to the need for multiple pointer dereferences and conversion between linear indexes and(segment, offset)pairs - Direct slicing is unavailable (i.e. no
&[T]or&mut [T]), thoughsliceandslice_mutare available
§Use Cases
- You have a long-lived
Vecwhose size fluctuates between very large and very small throughout the life of the program. - You have a large append-only
Vecand would benefit from stable references to the elements
§Features
small-vec- UsesSmallVecinstead ofVecto store the list of segments, allowing the first few segment headers to live on the stack. Can speed up access for smallSegVecvalues.thin-segments- UsesThinVecinstead ofVecto store the data for each segment, meaning that each segment header takes up the space of a singleusize, rathern than 3 when usingVec.
Modules§
Structs§
- Drain
- Removes and returns elements from a range in a
SegVec. Any un-consumed elements are removed and dropped when aDrainis dropped. If aDrainis forgotten (viastd::mem::forget), it is unspecified how many elements are removed. The current implementation callsSegVec::removeon a single element on each call tonext. - Exponential
- Exponential growth, each subsequent segment is as big as the sum of all segments before.
- Into
Iter - Consuming iterator over items in a
SegVec. - Iter
- Iterator over immutable references to items in a
SegVec. - Linear
- Linear growth, all segments have the same (FACTOR) length.
- Proportional
- Proportional growth, each segment is segment_number*FACTOR sized.
- SegVec
- A data structure similar to
Vec, but that does not copy on re-size and can release memory when it is truncated. - Segmented
Iter - Iterator over immutable references to slices of the elements of a
Slice. - Segmented
MutIter - Iterator over mutable references to slices of the elements of a
SliceMut. - Slice
- Provides an immutable view of elements from a range in
SegVec. - Slice
Iter - Iterator over immutable references to the elements of a
Slice. - Slice
Mut - Provides a mutable view of elements from a range in
SegVec. - Slice
MutIter - Iterator over immutable references to the elements of a
SliceMut.
Traits§
- MemConfig
- Configures the sizes of segments and how to index entries.
Linear,ProportionalandExponentialimplement this trait.