https://github.com/tafia/nested
A memory efficient container for rust nested collections
https://github.com/tafia/nested
containers heap memory rust
Last synced: about 1 month ago
JSON representation
A memory efficient container for rust nested collections
- Host: GitHub
- URL: https://github.com/tafia/nested
- Owner: tafia
- License: mit
- Created: 2017-12-29T03:39:53.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-09-04T13:23:16.000Z (almost 3 years ago)
- Last Synced: 2025-01-03T07:20:34.648Z (5 months ago)
- Topics: containers, heap, memory, rust
- Language: Rust
- Size: 8.79 KB
- Stars: 39
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: Changelog.md
- License: LICENSE-MIT.md
Awesome Lists containing this project
README
# nested
[](https://travis-ci.org/tafia/nested)
[](https://crates.io/crates/nested)A memory efficient container for nested collections.
This crate is intended to be used when:
- you want a potentially large:
- `Vec`
- `Vec>`
- `Vec` where `C` is heap allocated, dynamically sized and can implement `Collection` trait
- you actually only need to use borrowed items (`&[T]` or `&str`)Instead of having n + 1 allocations, you'll only have 2.
## Example
```rust
use nested::Nested;let mut v = Nested::::new();
// you can either populate it one by one
v.push("a");
v.push("bb".to_string());
v.push("hhh");
v.extend(vec!["iiiiii".to_string(), "jjjj".to_string()]);
assert_eq!(v.len(), 5);
assert_eq!(&v[0], "a");
assert_eq!(&v[1], "bb");// or you can directly collect it
let mut v = ["a", "b", "c", "d", "e", "f", "g"].iter().collect::>();
assert_eq!(v.len(), 7);// it also provides basic operations
let u = v.split_off(2);
assert_eq!(u.get(0), Some("c"));v.truncate(1);
assert_eq!(v.pop(), Some("a".to_string()));
assert_eq!(v.pop(), None);
```## Benches
See benches directory.
Here are the benches for collecting all words in src/lib.rs file:
```
test bench_nested_string ... bench: 55,381 ns/iter (+/- 7,852)
test bench_nested_string_iter ... bench: 95,127 ns/iter (+/- 8,253)
test bench_vec_string ... bench: 117,203 ns/iter (+/- 13,089)
test bench_vec_string_iter ... bench: 142,245 ns/iter (+/- 24,701)
```## Licence
MIT