cql_nullable_f64

Crates.iocql_nullable_f64
lib.rscql_nullable_f64
version0.2.2
sourcesrc
created_at2020-02-10 17:39:30.450595
updated_at2020-03-11 14:20:26.473171
descriptionNullable f64 storage support for CQL Database - a lightweight array-based database
homepage
repositoryhttps://github.com/AndrewSisley/CQLDb/
max_upload_size
id207076
size32,822
(AndrewSisley)

documentation

README

CQL NullableF64

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

Will allocate 9 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 (ns)
Single point read 1 3 100 (+/- 200)
Single point read 4 16 400 (+/- 900)
Single point write 1 2 800 (+/- 300)
Single point write 4 15 400 (+/- 1 000)
Stream read 1 point 1 2 500 (+/- 300)
Stream read 1 point 4 15 300 (+/- 800)
Stream read 50 000 points 1 27 300 000 (+/- 500 000)
Stream read 50 000 points 4 27 500 000 (+/- 150 000)

Getting started

To get started, add the below dependencies to your Cargo.toml:

[dependencies]
//... (any existing dependencies you may have)
cql_db = "^0.2.4"
cql_nullable_f64 = "^0.2"

Then need to create a folder where you want the database to live, and then try out the below:

use std::io::{ Cursor, SeekFrom, Seek };
use std::error::Error;
use cql_nullable_f64::{ NullableF64, unpack_stream };

const DATABASE_LOCATION: &str = "PATH_TO_YOUR_DATABASE_DIRECTORY";

pub fn example_cql() -> Result<(), Error> {
    // create a one dimensional database to hold 3 points
    cql_db::create_db::<NullableF64>(
        DATABASE_LOCATION,
        &[3]
    )?;

    // write '-1.6', to [1]
    cql_db::write_value::<NullableF64>(
        DATABASE_LOCATION,
        &[1],
        Some(-1.6)
    )?;

    // write '5.4', to [3]
    cql_db::write_value::<NullableF64>(
        DATABASE_LOCATION,
        &[3],
        Some(5.4)
    )?;

    let mut result: [Option<f64>; 3] = [None; 3];
    let mut stream = Cursor::new(Vec::new());

    // read 3 values from [1] to 'stream'
    cql_db::read_to_stream::<NullableF64>(
        DATABASE_LOCATION,
        &mut stream,
        &[1],
        3
    )?;

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

    assert_eq!(result[0], Some(-1.6));
    assert_eq!(result[1], None);
    assert_eq!(result[2], Some(5.4));
    Ok(())
}

More info

For further information and more examples, please see the rustdocs. Additional storage types are documented in the cql_db crate.

Commit count: 420

cargo fmt