Crates.io | smolvec |
lib.rs | smolvec |
version | 1.0.0 |
source | src |
created_at | 2024-10-13 06:25:58.423384 |
updated_at | 2024-10-13 06:25:58.423384 |
description | A lightweight vector implementation with small-vector optimization for rust. |
homepage | |
repository | https://github.com/simplysabir/smolvec |
max_upload_size | |
id | 1407107 |
size | 15,873 |
SmolVec is a lightweight vector implementation with small-vector optimization for Rust, providing excellent performance for small collections while maintaining API compatibility with the standard Vec<T>
.
Vec<T>
Based on our benchmarks:
std::Vec
for small push operationsstd::Vec
for small pop operationsstd::Vec
outperforms SmolVec in push operationsThese results demonstrate that SmolVec is particularly efficient for use cases involving small collections or frequent creation and destruction of vectors.
Add this to your Cargo.toml
:
[dependencies]
smolvec = "1.0.0"
Then, in your Rust code:
use smolvec::SmolVec;
fn main() {
let mut vec = SmolVec::new();
vec.push(1);
vec.push(2);
vec.push(3);
println!("Vector: {:?}", vec);
// SmolVec implements standard Vec methods
vec.pop();
vec.extend([4, 5, 6].iter().cloned());
println!("Modified vector: {:?}", vec);
}
SmolVec is ideal for scenarios where:
For consistently large collections, consider using the standard Vec<T>
instead.
For full documentation, including all available methods and their usage, run cargo doc --open
after adding SmolVec to your project dependencies.
To run the benchmarks yourself:
cargo bench
This will execute the benchmark suite and provide detailed performance comparisons between SmolVec and std::Vec.
This project is licensed under
at your option.
Contributions are welcome! Please feel free to submit a Pull Request. Here are some ways you can contribute:
Before making a significant change, please open an issue to discuss your proposed changes and ensure they align with the project's goals.