Compatibility: HashMap

perennial@0.1.0Updated 9 min readView as markdown

Spec: docs/spec/hashmap-1.md, docs/spec/hashmap-2.md, docs/spec/set-algebra.md, docs/spec/hashing.md, docs/spec/ordering-and-equality.md. Legend and 01: labels: ../COMPAT.md. GenericHashMap rows are in crate.md, HashMapPool rows in features.md; OrdMap: From<HashMap> rows are in ordmap.md (the target type's file owns a conversion).

Lookup bounds follow im (BK: Hash + Eq + ?Sized, K: Borrow<BK>, 01:bounds); imbl's Equivalent-based bounds are not a separate row (see COMPAT.md, shape decisions).

Type, constructors, hasher

item im 15.1 imbl 7 perennial status test
HashMap<K, V, S = RandomState> (type) struct with hasher parameter alias HashMap<K, V> only (no S) alias of GenericHashMap<K, V, S, P> keeping S = RandomState (01:generic) same tests/compat_hashmap.rs::hash_map_type
new() -> Self fresh RandomState per map as im as im (needs feature std) same tests/compat_hashmap.rs::new
with_pool(pool: &HashMapPool<K, V>) -> Self im-rc pool absent size-only handle differs: pool does not pool allocations (01:pools) tests/compat_hashmap_features.rs::with_pool
unit(k: K, v: V) -> HashMap<K, V> one mapping as im (returns generic type) as im same tests/compat_hashmap.rs::unit
with_hasher<RS>(h: RS) -> Self where Rc<S>/Arc<S>: From<RS> accepts S or the pointer takes S accepts anything Into<Ptr<S>>, so both call forms compile (01:bounds) same tests/compat_hashmap.rs::with_hasher
with_pool_hasher<RS>(pool, h: RS) -> Self im-rc pool absent size-only handle differs: pool does not pool allocations (01:pools) tests/compat_hashmap_features.rs::with_pool_hasher
hasher(&self) -> &Rc<S> / &Arc<S> pointer to builder returns &S returns &Ptr<S> (01:bounds) same tests/compat_hashmap.rs::hasher
new_from<K1, V1>(&self) -> HashMap<K1, V1, S> empty map sharing the hasher instance as im as im same tests/compat_hashmap.rs::new_from
pool(&self) -> &HashMapPool<K, V> im-rc pool; size 0 if none absent size-only handle differs: handle only (01:pools) tests/compat_hashmap_features.rs::pool

Queries

item im 15.1 imbl 7 perennial status test
is_empty(&self) -> bool O(1) as im as im same tests/compat_hashmap.rs::is_empty
len(&self) -> usize O(1) as im as im same tests/compat_hashmap.rs::len
ptr_eq(&self, other: &Self) -> bool clone → true; two empty new() → false two empty → true two empty → true differs: empty maps are ptr_eq (01:ptr_eq-empty) tests/compat_hashmap.rs::ptr_eq
iter(&self) -> Iter<'_, K, V> hash order, stable per map value as im order contract of hashing.md (exact order not reproduced) same tests/differential/hashmap.rs
keys(&self) -> Keys<'_, K, V> same order as iter as im as im same tests/compat_hashmap.rs::keys
values(&self) -> Values<'_, K, V> same order as iter as im as im same tests/compat_hashmap.rs::values
clear(&mut self) O(n); observed to leak elements if a Drop panics as im as im, but drops the remaining elements rather than leaking (spec preference) same tests/compat_hashmap.rs::clear
get<BK>(&self, k: &BK) -> Option<&V> as im as im same tests/compat_hashmap.rs::get
get_key_value<BK>(&self, k: &BK) -> Option<(&K, &V)> stored key and value as im as im same tests/compat_hashmap.rs::get_key_value
contains_key<BK>(&self, k: &BK) -> bool as im as im same tests/compat_hashmap.rs::contains_key
is_submap_by<B, RM, F>(&self, other: RM, cmp: F) -> bool every key of self in other and cmp holds adds P2 generic as im same tests/compat_hashmap.rs::is_submap_by
is_proper_submap_by<B, RM, F>(&self, other: RM, cmp: F) -> bool submap and strictly smaller as im as im same tests/compat_hashmap.rs::is_proper_submap_by
is_submap<RM>(&self, other: RM) -> bool (V: PartialEq) as im as im same tests/compat_hashmap.rs::is_submap
is_proper_submap<RM>(&self, other: RM) -> bool as im as im same tests/compat_hashmap.rs::is_proper_submap

Mutation

item im 15.1 imbl 7 perennial status test
iter_mut(&mut self) -> IterMut<'_, K, V> copy-on-write as im as im same tests/compat_hashmap.rs::iter_mut
get_mut<BK>(&mut self, k: &BK) -> Option<&mut V> as im as im same tests/compat_hashmap.rs::get_mut
get_key_value_mut<Q>(&mut self, k: &Q) -> Option<(&K, &mut V)> absent present provided, im-style bounds (01 "imbl additions kept") added (imbl API) tests/compat_hashmap.rs::get_key_value_mut
insert(&mut self, k: K, v: V) -> Option<V> old value; key object replaced too as im as im same tests/compat_hashmap.rs::insert
remove<BK>(&mut self, k: &BK) -> Option<V> as im as im same tests/compat_hashmap.rs::remove
remove_with_key<BK>(&mut self, k: &BK) -> Option<(K, V)> as im as im same tests/compat_hashmap.rs::remove_with_key
entry(&mut self, k: K) -> Entry<'_, K, V, S> hashes once adds P as im same tests/compat_hashmap.rs::entry
retain(&mut self, f: FnMut(&K, &V) -> bool) as im as im same tests/compat_hashmap.rs::retain

Persistent operations (receiver unchanged)

item im 15.1 imbl 7 perennial status test
update(&self, k: K, v: V) -> Self persistent insert as im as im same tests/compat_hashmap.rs::update
update_with(&self, k, v, f: FnOnce(V, V) -> V) -> Self f(old, new) when present as im as im same tests/compat_hashmap.rs::update_with
update_with_key(&self, k, v, f: FnOnce(&K, V, V) -> V) -> Self as im as im same tests/compat_hashmap.rs::update_with_key
update_lookup_with_key(&self, k, v, f: FnOnce(&K, &V, V) -> V) -> (Option<V>, Self) previous value; f only when present as im as im same tests/compat_hashmap.rs::update_lookup_with_key
alter(&self, f: FnOnce(Option<V>) -> Option<V>, k: K) -> Self closure first; None removes as im as im same tests/compat_hashmap.rs::alter
without<BK>(&self, k: &BK) -> Self unchanged copy if absent as im as im same tests/compat_hashmap.rs::without
extract<BK>(&self, k: &BK) -> Option<(V, Self)> as im as im same tests/compat_hashmap.rs::extract
extract_with_key<BK>(&self, k: &BK) -> Option<(K, V, Self)> as im as im same tests/compat_hashmap.rs::extract_with_key

Set-like combinations (consume both maps)

item im 15.1 imbl 7 perennial status test
union(self, other: Self) -> Self larger map's value wins, self on a tie; result keeps the larger map's hasher self always wins self always wins and the result keeps self's hasher differs: self wins regardless of size (01:union) tests/compat_hashmap.rs::union
union_with(self, other, f: FnMut(V, V) -> V) -> Self f(self_v, other_v) regardless of sizes as im as im same tests/compat_hashmap.rs::union_with
union_with_key(self, other, f: FnMut(&K, V, V) -> V) -> Self as union_with as im as im same tests/compat_hashmap.rs::union_with_key
unions(i: impl IntoIterator<Item = Self>) -> Self folds union, so size rule applies leftmost wins leftmost wins differs: follows the union rule (01:union) tests/compat_hashmap.rs::unions
unions_with(i, f: Fn(V, V) -> V) -> Self folds left as im as im same tests/compat_hashmap.rs::unions_with
unions_with_key(i, f: Fn(&K, V, V) -> V) -> Self folds left as im as im same tests/compat_hashmap.rs::unions_with_key
difference(self, other: Self) -> Self alias of symmetric_difference same, #[deprecated] (2.0.1) same, deprecated differs: carries a deprecation warning, behaviour unchanged (01:difference) tests/compat_hashmap.rs::difference
symmetric_difference(self, other: Self) -> Self in exactly one map as im as im same tests/compat_hashmap.rs::symmetric_difference
difference_with(self, other, f: FnMut(V, V) -> Option<V>) -> Self alias deprecated deprecated differs: deprecation warning only (01:difference) tests/compat_hashmap.rs::difference_with
symmetric_difference_with(self, other, f: FnMut(V, V) -> Option<V>) -> Self Some keeps, None drops shared keys as im as im same tests/compat_hashmap.rs::symmetric_difference_with
difference_with_key(self, other, f: FnMut(&K, V, V) -> Option<V>) -> Self alias deprecated deprecated differs: deprecation warning only (01:difference) tests/compat_hashmap.rs::difference_with_key
symmetric_difference_with_key(self, other, f: FnMut(&K, V, V) -> Option<V>) -> Self as im as im same tests/compat_hashmap.rs::symmetric_difference_with_key
relative_complement(self, other: Self) -> Self in self, not in other; O(m log n) as im as im same tests/compat_hashmap.rs::relative_complement
intersection(self, other: Self) -> Self keeps self's values as im as im same tests/compat_hashmap.rs::intersection
intersection_with<B, C, F>(self, other: HashMap<K, B, S>, f: FnMut(V, B) -> C) -> HashMap<K, C, S> adds pointer generics as im same tests/compat_hashmap.rs::intersection_with
intersection_with_key<B, C, F>(self, other, f: FnMut(&K, V, B) -> C) -> HashMap<K, C, S> as im as im same tests/compat_hashmap.rs::intersection_with_key

Entry API (module hashmap; imbl adds a trailing P to all three types)

item im 15.1 imbl 7 perennial status test
Entry<'a, K, V, S> (enum Occupied, Vacant) key hashed once at creation; no Debug adds P as im (01:generic) same tests/compat_hashmap.rs::entry_type
Entry::or_insert(self, d: V) -> &'a mut V as im as im same tests/compat_hashmap.rs::entry_or_insert
Entry::or_insert_with(self, f: FnOnce() -> V) -> &'a mut V as im as im same tests/compat_hashmap.rs::entry_or_insert_with
Entry::or_default(self) -> &'a mut V (V: Default) as im as im same tests/compat_hashmap.rs::entry_or_default
Entry::key(&self) -> &K stored key if occupied, given key if vacant; never inserts as im as im same tests/compat_hashmap.rs::entry_key
Entry::and_modify(self, f: FnOnce(&mut V)) -> Self runs only if occupied as im as im same tests/compat_hashmap.rs::entry_and_modify
OccupiedEntry<'a, K, V, S> (type) adds P as im same tests/compat_hashmap.rs::occupied_entry_type
OccupiedEntry::key(&self) -> &K as im as im same tests/compat_hashmap.rs::occupied_entry_key
OccupiedEntry::get(&self) -> &V as im as im same tests/compat_hashmap.rs::occupied_entry_get
OccupiedEntry::get_mut(&mut self) -> &mut V as im as im same tests/compat_hashmap.rs::occupied_entry_get_mut
OccupiedEntry::into_mut(self) -> &'a mut V as im as im same tests/compat_hashmap.rs::occupied_entry_into_mut
OccupiedEntry::insert(&mut self, v: V) -> V old value; key unchanged as im as im same tests/compat_hashmap.rs::occupied_entry_insert
OccupiedEntry::remove(self) -> V as im as im same tests/compat_hashmap.rs::occupied_entry_remove
OccupiedEntry::remove_entry(self) -> (K, V) as im as im same tests/compat_hashmap.rs::occupied_entry_remove_entry
VacantEntry<'a, K, V, S> (type) adds P as im same tests/compat_hashmap.rs::vacant_entry_type
VacantEntry::key(&self) -> &K as im as im same tests/compat_hashmap.rs::vacant_entry_key
VacantEntry::into_key(self) -> K as im as im same tests/compat_hashmap.rs::vacant_entry_into_key
VacantEntry::insert(self, v: V) -> &'a mut V as im as im same tests/compat_hashmap.rs::vacant_entry_insert

Iterator types (none double-ended; size_hint exact)

item im 15.1 imbl 7 perennial status test
hashmap::Iter<'a, K, V> (Item (&K, &V)) Iterator, ExactSize, Fused adds Clone as im plus Clone same tests/compat_hashmap.rs::iter_type
impl Clone for hashmap::Iter absent present provided (01 "imbl additions kept") added (imbl API) tests/compat_hashmap.rs::iter_impl_clone
hashmap::IterMut<'a, K, V> (Item (&K, &mut V)) Iterator, ExactSize, Fused as im as im same tests/compat_hashmap.rs::iter_mut_type
hashmap::Keys<'a, K, V> (Item &K) Iterator, ExactSize, Fused as im as im same tests/compat_hashmap.rs::keys_type
hashmap::Values<'a, K, V> (Item &V) Iterator, ExactSize, Fused as im as im same tests/compat_hashmap.rs::values_type
hashmap::ConsumingIter<A> (Item (K, V)) Iterator, ExactSize, Fused; declared with an internal bound adds Clone (7.0.2) usable as the IntoIter type, plus Clone; internal bound not reproduced (spec permits) same tests/compat_hashmap.rs::consuming_iter_type
impl Clone for hashmap::ConsumingIter absent present provided (01 "imbl additions kept") added (imbl API) tests/compat_hashmap.rs::consuming_iter_impl_clone

Trait implementations

item im 15.1 imbl 7 perennial status test
impl Clone O(1), shares hasher as im as im same tests/compat_hashmap.rs::impl_clone
impl Default (S: BuildHasher + Default) as im as im same tests/compat_hashmap.rs::impl_default
impl Debug {k: v, ...} in iteration order; stable bound K: Hash + Eq + Debug, V: Debug, S: BuildHasher bound K: Debug, V: Debug format as im; bound loosened to imbl's K: Debug, V: Debug (01:loose-bounds) same tests/differential/hashmap.rs
impl PartialEq (same S) content equality across hasher instances; NaN map != its clone as im as im same tests/differential/hashmap.rs
impl PartialEq<GenericHashMap<K, V, S2, P2>> absent present provided (01 "imbl additions kept") added (imbl API) tests/compat_hashmap.rs::impl_partial_eq_other_hasher
impl Eq (V: Eq) as im as im same tests/compat_hashmap.rs::impl_eq
impl PartialOrd lexicographic over iteration order (hasher-dependent) removed kept; compares sorted contents differs: order-independent comparison (01:ord) tests/compat_hashmap.rs::impl_partial_ord
impl Ord as PartialOrd removed kept; compares sorted contents differs: order-independent comparison (01:ord) tests/compat_hashmap.rs::impl_ord
impl Hash entries in iteration order, no length prefix; equal maps can hash differently removed kept; order-independent, equal maps hash equally differs: consistent with Eq (01:hash) tests/compat_hashmap.rs::impl_hash
impl Index<&BK> missing key panics HashMap::index: invalid key as im as im same tests/compat_hashmap.rs::impl_index
impl IndexMut<&BK> missing key panics HashMap::index_mut: invalid key as im as im same tests/compat_hashmap.rs::impl_index_mut
impl Add for HashMap<K, V, S> union (size rule) union (self wins) union (self wins) differs: follows union (01:union) tests/compat_hashmap.rs::impl_add
impl Add for &HashMap<K, V, S> union union union (self wins) differs: follows union (01:union) tests/compat_hashmap.rs::impl_add_ref
impl Sum (S: BuildHasher + Default) unions all (size rule) leftmost wins leftmost wins differs: follows union (01:union) tests/compat_hashmap.rs::impl_sum
impl Extend<(RK, RV)> (K: From<RK>, V: From<RV>) later items overwrite as im as im same tests/compat_hashmap.rs::impl_extend
impl FromIterator<(K, V)> later duplicates overwrite as im as im same tests/compat_hashmap.rs::impl_from_iterator
impl IntoIterator for HashMap ConsumingIter, same order as iter as im as im same tests/compat_hashmap.rs::impl_into_iterator
impl IntoIterator for &HashMap Iter as im as im same tests/compat_hashmap.rs::impl_into_iterator_ref
impl AsRef<HashMap<K, V, S>> itself as im as im same tests/compat_hashmap.rs::impl_as_ref
impl From<Vec<(K, V)>> as im as im same tests/compat_hashmap.rs::impl_from_vec
impl From<&Vec<(K, V)>> as im as im same tests/compat_hashmap.rs::impl_from_vec_ref
impl From<&[(K, V)]> as im as im same tests/compat_hashmap.rs::impl_from_slice
impl From<BTreeMap<K, V>> as im as im same tests/compat_hashmap.rs::impl_from_btree_map
impl From<&BTreeMap<K, V>> as im as im same tests/compat_hashmap.rs::impl_from_btree_map_ref
impl From<std::collections::HashMap<K, V>> as im as im same tests/compat_hashmap.rs::impl_from_std_hash_map
impl From<&std::collections::HashMap<K, V>> as im as im same tests/compat_hashmap.rs::impl_from_std_hash_map_ref
impl From<&HashMap<&K, &V, SA>> for HashMap<OK, OV, SB> owning copy via ToOwned as im as im same tests/compat_hashmap.rs::impl_from_map_of_refs
impl Serialize (feature serde) as a map, iteration order as im as im same tests/compat_hashmap_features.rs::impl_serialize
impl Deserialize (feature serde) from a map; duplicate keys: last wins as im as im same tests/compat_hashmap_features.rs::impl_deserialize
impl arbitrary::Arbitrary<'a> (feature arbitrary) yes yes yes same tests/compat_hashmap_features.rs::impl_arbitrary
impl quickcheck::Arbitrary (feature quickcheck) im only yes both crates (01:features) same tests/compat_hashmap_features.rs::impl_quickcheck_arbitrary
impl bincode::Encode / Decode (feature bincode) absent yes not provided not provided: imbl-only, not in im's API; not in 0.1 (01:imbl-only) —
auto traits Send / Sync im-rc neither; im when contents are as im perennial-rc neither; perennial when contents are same tests/compat_hashmap.rs::auto_traits

Behaviour covered by the model tests (not separate items)

Iteration-order contract (hashing.md properties 1–5), hasher sharing through clone and new_from, equality across hasher instances, and correct set operations between maps with different hasher instances are checked in tests/differential/hashmap.rs; the exact hash order observed in im is not reproduced and is not a compatibility claim.