This crate provides the SegVec
data structure.
It is similar to Vec
, but allocates memory in chunks of increasing size, referred to as
"segments". This involves a few trade-offs:
- Element addresses are stable across
push
operations even if theSegVec
must grow. - Resizing only allocates the additional space needed, and doesn't require copying.
- Operations are slower (some, like
insert
,remove
, anddrain
, are much slower) for aSegVec
than for aVec
(multiple pointer dereferences, mapping indices to(segment, offset)
pairs) - Direct slicing is unavailable (i.e. no
&[T]
or&mut [T]
), thoughslice
andslice_mut
are available
- You have a long-lived
Vec
whose size fluctuates between very large and very small throughout the life of the program. - You have a large append-only
Vec
and would benefit from stable references to the elements
small-vec
- UsesSmallVec
instead ofVec
to store the list of segments, allowing the first few segment headers to live on the stack. Can speed up access for smallSegVec
values.thin-segments
- UsesThinVec
instead ofVec
to store the data for each segment, meaning that each segment header takes up the space of a singleusize
, rathern than 3 when usingVec
.
License: MIT