Skip to content

Commit aede305

Browse files
committed
Add feature for amortized resizes
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.
1 parent 1d19552 commit aede305

File tree

5 files changed

+33
-13
lines changed

5 files changed

+33
-13
lines changed

azure-pipelines.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,22 @@ stages:
77
dir: "left-right"
88
- stage: evmap
99
jobs:
10-
- template: default.yml@templates
10+
- template: nightly-only.yml@templates
1111
parameters:
12-
minrust: 1.40.0
1312
codecov_token: $(CODECOV_TOKEN_SECRET)
1413
dir: "evmap"
14+
- job: features
15+
displayName: "Check feature combinations"
16+
pool:
17+
vmImage: ubuntu-latest
18+
steps:
19+
- template: install-rust.yml@templates
20+
parameters:
21+
rust: nightly
22+
- script: cargo install cargo-hack
23+
displayName: install cargo-hack
24+
- script: cargo hack --feature-powerset check
25+
displayName: cargo hack
1526
- job: benchmark
1627
displayName: "Check that benchmark compiles"
1728
pool:

evmap/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ maintenance = { status = "passively-maintained" }
2020
default = []
2121
indexed = ["indexmap"]
2222
eviction = ["indexed", "rand"]
23+
amortize = ["indexmap-amortized", "hashbag/amortize"]
2324

2425
[dependencies]
2526
indexmap = { version = "1.1.0", optional = true }
27+
indexmap-amortized = { version = "1.0.0", optional = true }
2628
smallvec = "1.0.0"
27-
hashbag = "0.1.2"
29+
hashbag = "0.1.3"
2830
rand = { version = "0.7", default-features = false, features = ["alloc"], optional = true }
2931
left-right = "0.9.1"
3032

evmap/src/inner.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use std::fmt;
22
use std::hash::{BuildHasher, Hash};
33

4-
#[cfg(feature = "indexed")]
5-
pub(crate) use indexmap::IndexMap as MapImpl;
6-
#[cfg(not(feature = "indexed"))]
7-
pub(crate) use std::collections::HashMap as MapImpl;
4+
#[cfg(all(feature = "indexed", not(feature = "amortize")))]
5+
pub(crate) use indexmap::{map::Entry, IndexMap as MapImpl};
6+
#[cfg(feature = "amortize")]
7+
pub(crate) use indexmap_amortized::{map::Entry, IndexMap as MapImpl};
8+
#[cfg(not(any(feature = "indexed", feature = "amortize")))]
9+
pub(crate) use std::collections::{hash_map::Entry, HashMap as MapImpl};
810

911
use crate::values::ValuesInner;
1012
use left_right::aliasing::DropBehavior;

evmap/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@
2828
//! meta will also be made visible to readers. This could be useful, for example, to indicate what
2929
//! time the refresh happened.
3030
//!
31+
//! # Features
32+
//!
33+
//! - `eviction`: Gives you access to [`WriteHandle::empty_random`] to empty out randomly chosen
34+
//! keys from the map.
35+
//! - `amortize`: Amortizes the cost of resizes in the underlying data structures. See
36+
//! [`griddle`](https://github.com/jonhoo/griddle/) and
37+
//! [`atone`](https://github.com/jonhoo/atone/) for details. This requires a nightly compiler
38+
//! [for the time being](https://docs.rs/indexmap-amortized/1.0/indexmap_amortized/#rust-version).
39+
//!
40+
//!
3141
//! # Examples
3242
//!
3343
//! Single-reader, single-writer

evmap/src/write.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::inner::Inner;
1+
use crate::inner::{Entry, Inner};
22
use crate::read::ReadHandle;
33
use crate::values::ValuesInner;
44
use left_right::{aliasing::Aliased, Absorb};
@@ -7,11 +7,6 @@ use std::collections::hash_map::RandomState;
77
use std::fmt;
88
use std::hash::{BuildHasher, Hash};
99

10-
#[cfg(feature = "indexed")]
11-
use indexmap::map::Entry;
12-
#[cfg(not(feature = "indexed"))]
13-
use std::collections::hash_map::Entry;
14-
1510
/// A handle that may be used to modify the eventually consistent map.
1611
///
1712
/// Note that any changes made to the map will not be made visible to readers until

0 commit comments

Comments
 (0)