#array #variables #serde #benefits #length #vec #replace

heap-array

An Implementation of a variable length array, with its main benefit over Vec is taking up less space

8 releases

new 0.1.8 Apr 11, 2024
0.1.7 Jan 10, 2024
0.1.6 Dec 30, 2023
0.1.3 Aug 27, 2023

#590 in Encoding

Download history 17/week @ 2023-12-25 7/week @ 2024-01-08 16/week @ 2024-02-26 4/week @ 2024-03-11 54/week @ 2024-04-01

58 downloads per month
Used in ilgda-ipc

MIT license

77KB
935 lines

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

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])
}

lib.rs:

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

Examples

use heap_array::{heap_array, HeapArray};
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])

Dependencies

~0–1.4MB
~26K SLoC