Expand description
This crate implements various CqlType derivatives for storing u64
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) | Mean time (ns) |
---|---|---|---|
Single point read | 1 | 2 450 (+/- 300) | 7 500 (+/- 600) |
Single point read | 4 | 14 850 (+/- 1 000) | 37 550 (+/- 2 300) |
Single point write | 1 | 2 800 (+/- 400) | 7 700 (+/- 400) |
Single point write | 4 | 15 400 (+/- 2 500) | 37 700 (+/- 3 000) |
Stream read 1 point | 1 | 2 500 (+/- 300) | 10 000 (+/- 850) |
Stream read 1 point | 4 | 14 900 (+/- 600) | 42 500 (+/- 6 500) |
Stream read 50 000 points | 1 | 27 650 000 (+/- 31 000) | 27 630 000 (+/- 180 000) |
Stream read 50 000 points | 4 | 27 660 000 (+/- 1 200 000) | 27 620 000 (+/- 480 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::<U64>(
DATABASE_LOCATION,
&[3]
)?;
cql_db::write_value::<U64>(
DATABASE_LOCATION,
&base_point,
value1
)?;
cql_db::write_value::<U64>(
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::<U64>(
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§
- U64
- Static struct for declaring that you want to work with
u64
values in a CQL database.
Functions§
- unpack_
stream - Unpacks
n_values
of u64 from a stream, callingvalue_handler
with each value and it’s index.