#cql #storage #array

cql_f64

f64 storage support for CQL Database - a lightweight array-based database

1 unstable release

0.2.0 Sep 26, 2020

#30 in #cql

MIT/Apache

15KB
80 lines

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

Will allocate 8 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.

Operation Database dimensions Mean time _unchecked (ns)
Single point read 1 2 610 (+/- 150)
Single point read 4 15 500 (+/- 800)
Single point write 1 2 950 (+/- 250)
Single point write 4 16 500 (+/- 2 000)
Stream read 1 point 1 2 600 (+/- 200)
Stream read 1 point 4 15 400 (+/- 850)
Stream read 50 000 points 1 27 950 000 (+/- 150 000)
Stream read 50 000 points 4 27 930 000 (+/- 200 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.2;
let value3 = -5.6;

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

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

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

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

cql_db::read_to_stream::<F64>(
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.0);
assert_eq!(result[2], value3);

Dependencies

~115KB