Skip to main content

new_sparse

Function new_sparse 

Source
pub fn new_sparse<T>(
    len: usize,
    num_values: usize,
) -> PartialArrayBuilder<T, EliasFanoBuilder>
Expand description

Creates a new builder for a sparse partial array of the given length.

A sparse partial array stores the non-empty positions of the array in an Elias-Fano structure.

If your set of values is really dense, consider using a dense partial array.

ยงExamples

use sux::array::partial_array;

let mut builder = partial_array::new_sparse(10, 3);
builder.set(1, "foo");
builder.set(2, "hello");
builder.set(7, "world");

let array = builder.build();
assert_eq!(array.get(1), Some(&"foo"));
assert_eq!(array.get(2), Some(&"hello"));
assert_eq!(array.get(3), None);
assert_eq!(array.get(7), Some(&"world"));

Note that you must specify the number of values in advance.