diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 8f35643..a10d85b 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -9,7 +9,7 @@ stages: jobs: - template: default.yml@templates parameters: - minrust: 1.40.0 + minrust: 1.48.0 codecov_token: $(CODECOV_TOKEN_SECRET) dir: "evmap" - job: benchmark diff --git a/evmap/Cargo.toml b/evmap/Cargo.toml index 7d9ebce..2fd3808 100644 --- a/evmap/Cargo.toml +++ b/evmap/Cargo.toml @@ -20,11 +20,13 @@ maintenance = { status = "passively-maintained" } default = [] indexed = ["indexmap"] eviction = ["indexed", "rand"] +amortize = ["indexmap-amortized", "hashbag/amortize"] [dependencies] -indexmap = { version = "1.1.0", optional = true } +indexmap = { version = "1.6.1", optional = true } +indexmap-amortized = { version = "1.6.1", optional = true } smallvec = "1.0.0" -hashbag = "0.1.2" +hashbag = "0.1.3" rand = { version = "0.7", default-features = false, features = ["alloc"], optional = true } left-right = { version = "0.11.0" } #, path = "../left-right", } diff --git a/evmap/src/inner.rs b/evmap/src/inner.rs index de96739..298b68d 100644 --- a/evmap/src/inner.rs +++ b/evmap/src/inner.rs @@ -1,10 +1,12 @@ use std::fmt; use std::hash::{BuildHasher, Hash}; -#[cfg(feature = "indexed")] -pub(crate) use indexmap::IndexMap as MapImpl; -#[cfg(not(feature = "indexed"))] -pub(crate) use std::collections::HashMap as MapImpl; +#[cfg(all(feature = "indexed", not(feature = "amortize")))] +pub(crate) use indexmap::{map::Entry, IndexMap as MapImpl}; +#[cfg(feature = "amortize")] +pub(crate) use indexmap_amortized::{map::Entry, IndexMap as MapImpl}; +#[cfg(not(any(feature = "indexed", feature = "amortize")))] +pub(crate) use std::collections::{hash_map::Entry, HashMap as MapImpl}; use crate::values::ValuesInner; use left_right::aliasing::DropBehavior; diff --git a/evmap/src/lib.rs b/evmap/src/lib.rs index 9747869..c09c048 100644 --- a/evmap/src/lib.rs +++ b/evmap/src/lib.rs @@ -28,6 +28,16 @@ //! meta will also be made visible to readers. This could be useful, for example, to indicate what //! time the refresh happened. //! +//! # Features +//! +//! - `eviction`: Gives you access to [`WriteHandle::empty_random`] to empty out randomly chosen +//! keys from the map. +//! - `amortize`: Amortizes the cost of resizes in the underlying data structures. See +//! [`griddle`](https://github.com/jonhoo/griddle/) and +//! [`atone`](https://github.com/jonhoo/atone/) for details. This requires a nightly compiler +//! [for the time being](https://docs.rs/indexmap-amortized/1.0/indexmap_amortized/#rust-version). +//! +//! //! # Examples //! //! Single-reader, single-writer diff --git a/evmap/src/write.rs b/evmap/src/write.rs index 1f1a79c..e6fba60 100644 --- a/evmap/src/write.rs +++ b/evmap/src/write.rs @@ -1,4 +1,4 @@ -use crate::inner::Inner; +use crate::inner::{Entry, Inner}; use crate::read::ReadHandle; use crate::values::ValuesInner; use left_right::{aliasing::Aliased, Absorb}; @@ -7,11 +7,6 @@ use std::collections::hash_map::RandomState; use std::fmt; use std::hash::{BuildHasher, Hash}; -#[cfg(feature = "indexed")] -use indexmap::map::Entry; -#[cfg(not(feature = "indexed"))] -use std::collections::hash_map::Entry; - /// A handle that may be used to modify the eventually consistent map. /// /// Note that any changes made to the map will not be made visible to readers until