davenport

Crates.iodavenport
lib.rsdavenport
version0.1.1
sourcesrc
created_at2022-09-07 09:13:47.853785
updated_at2022-10-28 15:21:31.984075
descriptionErgonomic thread-local workspaces for intermediate data
homepage
repositoryhttps://github.com/Andlon/davenport
max_upload_size
id660232
size27,647
Andreas Borgen Longva (Andlon)

documentation

README

davenport

davenport is a Rust microcrate that provides ergonomic thread-local workspaces for intermediate data.

use davenport::{define_thread_local_workspace, with_thread_local_workspace};

#[derive(Default)]
pub struct MyWorkspace {
    index_buffer: Vec<usize>
}

define_thread_local_workspace!(WORKSPACE);

fn median_floor(indices: &[usize]) -> Option<usize> {
    with_thread_local_workspace(&WORKSPACE, |workspace: &mut MyWorkspace| {
        // Re-use buffer from previous call to this function
        let buffer = &mut workspace.index_buffer;
        buffer.clear();
        buffer.copy_from_slice(&indices);
        buffer.sort_unstable();
        buffer.get(indices.len() / 2).copied()
    })
}

See the documentation for an in-depth explanation of the crate.

License

Licensed under the terms of both MIT and Apache 2.0 at your option. See LICENSE-MIT and LICENSE-APACHE for the detailed license text.

Commit count: 15

cargo fmt