[][src]Crate cql_i16

This crate implements various CqlType derivatives for storing i16 values in a CQL database.

Will allocate 2 bytes per value linked.

Benchmarks

Benchmarks supplied below are fairly rudimentary (and rounded) and are there to give a rough idea of relative costs. Full benchmark code can be found in github and can be run with rustup run nightly cargo bench.

OperationDatabase dimensionsMean time _unchecked (ns)
Single point read12 520 (+/- 200)
Single point read415 300 (+/- 1 100)
Single point write12 800 (+/- 300)
Single point write415 350 (+/- 1 500)
Stream read 1 point12 500 (+/- 200)
Stream read 1 point415 400 (+/- 850)
Stream read 50 000 points127 600 000 (+/- 900 000)
Stream read 50 000 points427 400 000 (+/- 90 000)

Examples

The following creates a 1D database, writes 2 values to it, and then streams them into an array.

const N_VALUES_TO_READ: usize = 3;

let base_point = [1];
let value1 = 1;
let value3 = -5;

cql_db::create_db::<I16>(
    DATABASE_LOCATION,
    &[3]
)?;

cql_db::write_value::<I16>(
    DATABASE_LOCATION,
    &base_point,
    value1
)?;

cql_db::write_value::<I16>(
    DATABASE_LOCATION,
    &[base_point[0] + 2],
    value3
)?;

let mut result = [0; N_VALUES_TO_READ];
let mut stream = Cursor::new(Vec::new());

cql_db::read_to_stream::<I16>(
    DATABASE_LOCATION,
    &mut stream,
    &base_point,
    N_VALUES_TO_READ as u64
)?;

stream.seek(SeekFrom::Start(0)).unwrap();
unpack_stream(&mut stream, N_VALUES_TO_READ, |idx, value| {
    result[idx] = value
})?;

assert_eq!(result[0], value1);
assert_eq!(result[1], 0);
assert_eq!(result[2], value3);

Structs

I16

Static struct for declaring that you want to work with i16 values in a CQL database.

Functions

unpack_stream

Unpacks n_values of i16 from a stream, calling value_handler with each value and it's index.