Skip to content

Commit

Permalink
Add feature for amortized resizes
Browse files Browse the repository at this point in the history
Keep in mind that since this is a feature, _all_ evmap instances get
amortized if _anything_ in the dependency graph enables the feature
(indexmap-rs/indexmap#137 (comment)).
This is unfortunate, but given that the alternative is forking evmap,
we'll go with the feature approach for now. Hopefully one day we'll have
a way to [avoid this](rust-lang/cargo#2980 (comment)).

Not landing this yet since it's nightly-only at the moment due to
certain methods [in
`atone`](https://github.com/jonhoo/atone/blob/45ae1e42deaaaaa9a919957ade49982a7ac4655b/src/lib.rs#L58).
Nightly-only will go away once
rust-lang/rust#70929 and
rust-lang/rust#74217 both stabilize. The first
one will land on next stable, but the second has some more time to go
first.
  • Loading branch information
jonhoo committed Dec 17, 2020
1 parent e025511 commit 0ddc937
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
15 changes: 13 additions & 2 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,22 @@ stages:
dir: "left-right"
- stage: evmap
jobs:
- template: default.yml@templates
- template: nightly-only.yml@templates
parameters:
minrust: 1.40.0
codecov_token: $(CODECOV_TOKEN_SECRET)
dir: "evmap"
- job: features
displayName: "Check feature combinations"
pool:
vmImage: ubuntu-latest
steps:
- template: install-rust.yml@templates
parameters:
rust: nightly
- script: cargo install cargo-hack
displayName: install cargo-hack
- script: cargo hack --feature-powerset check
displayName: cargo hack
- job: benchmark
displayName: "Check that benchmark compiles"
pool:
Expand Down
4 changes: 3 additions & 1 deletion evmap/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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-amortized = { version = "1.0.0", 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", }

Expand Down
10 changes: 6 additions & 4 deletions evmap/src/inner.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
10 changes: 10 additions & 0 deletions evmap/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions evmap/src/write.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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
Expand Down

0 comments on commit 0ddc937

Please sign in to comment.