https://github.com/vrtgs/heap-array
An Implementation of a variable length array, with its main benefit over `Vec` is taking up less space
https://github.com/vrtgs/heap-array
Last synced: 4 months ago
JSON representation
An Implementation of a variable length array, with its main benefit over `Vec` is taking up less space
- Host: GitHub
- URL: https://github.com/vrtgs/heap-array
- Owner: Vrtgs
- License: mit
- Created: 2023-08-14T21:19:51.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-07-07T23:22:05.000Z (10 months ago)
- Last Synced: 2024-12-13T17:52:01.096Z (4 months ago)
- Language: Rust
- Size: 80.1 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# HeapArray
An Implementation of a variable length array, with its main benefit over `Vec` is taking up less space
as `HeapArray` is represented as (pointer, len) while Vec is a (pointer, len, capacity)
and is meant as a replacement for `Box<[T]>`nice to have: compatible with serde
# Example
```rust
use heap_array::{heap_array, HeapArray};fn main() {
let arr = heap_array![1, 2, 5, 8];assert_eq!(arr[0], 1);
assert_eq!(arr[1], 2);
assert_eq!(arr[2], 5);
assert_eq!(arr[3], 8);
assert_eq!(arr.len(), 4);let arr = HeapArray::from_fn(10, |i| i);
assert_eq!(*arr, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
}
```