Crates.io | davenport |
lib.rs | davenport |
version | 0.1.1 |
source | src |
created_at | 2022-09-07 09:13:47.853785 |
updated_at | 2022-10-28 15:21:31.984075 |
description | Ergonomic thread-local workspaces for intermediate data |
homepage | |
repository | https://github.com/Andlon/davenport |
max_upload_size | |
id | 660232 |
size | 27,647 |
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.
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.