cql_u64

Crates.iocql_u64
lib.rscql_u64
version0.2.3
sourcesrc
created_at2020-02-10 15:09:31.753657
updated_at2020-03-11 13:07:24.15738
descriptionu64 storage support for CQL Database - a lightweight array-based database
homepage
repositoryhttps://github.com/AndrewSisley/CQLDb/tree/master/cql_storage_types/cql_u64
max_upload_size
id207040
size26,585
(AndrewSisley)

documentation

README

CQL U64

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)

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_u64 = "^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 cql_db::error::Error;
use cql_u64::{ U64, 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::<U64>(
        DATABASE_LOCATION,
        &[3]
    )?;

    // write '1', to [1]
    cql_db::write_value::<U64>(
        DATABASE_LOCATION,
        &[1],
        1
    )?;

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

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

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

    assert_eq!(result[0], 1);
    assert_eq!(result[1], 0);
    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