Segvec
SegVec data structure for rust. Similar to Vec, but allocates memory in chunks of increasing size.
Install / Use
/learn @mccolljr/SegvecREADME
segvec
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:
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) for aSegVecthan for aVec(multiple pointer dereferences, mapping indices to(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.
License: MIT
Related Skills
node-connect
349.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.5kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
