auto-hash-map: add positional access and IndexMap/IndexSet conversions for ordered maps (#101497)
## What?
Adds positional access and `IndexMap`/`IndexSet` conversions to the
insertion-ordered auto collections (`OrderedAutoMap`/`OrderedAutoSet`):
- `get_index(i)` / `get_index_of(&key)` on ordered `RawAutoMap` and
`RawAutoSet`, backed by a new `IndexedBackingMapStorage` sub-trait of
`BackingMapStorage` (implemented for `IndexMap`). The index of an entry
is its position in iteration order, in both the list and the map
variant: a slice index and a linear scan (at most 32 entries) for lists,
and the `IndexMap` methods for maps.
- `From<IndexMap<K, V, H>>` for `RawAutoMap<K, V, IndexMap<K, V, H>,
L>`, keeping the order. Maps that fit into the list variant become a
list without rehashing; larger maps are moved in as they are.
- `From<IndexSet<K, H>>` for `RawAutoSet<K, IndexMap<K, (), H>, L>`,
keeping the order.
- `RawAutoMap::from_unique_iterator` /
`RawAutoSet::from_unique_iterator`: build from entries whose keys are
known to be unique without comparing keys in the list variant
(duplicates are a caller error, checked in debug builds). All `From`
conversions use it or move the backing map in.
- `From<hashbrown::HashMap/HashSet>` for `AutoMap`/`AutoSet` (large maps
are moved in) and `From<BTreeMap/BTreeSet>` for any
`RawAutoMap`/`RawAutoSet` (ordered storages keep the key order).
- Key lookups take `Q: Hash + Equivalent<K>` like hashbrown and indexmap
(`Equivalent` is re-exported). Every `Borrow` lookup keeps working;
custom `BackingMapStorage` impls need the new bounds and
`get_key_value`.
- `keys()` and `get_key_value()`.
## Why?
#100940 replaces the `OrderedIndexMap`/`OrderedIndexSet` newtypes with
`OrderedAutoMap`/`OrderedAutoSet`, and #101520 moves every remaining
`IndexMap`/`IndexSet` cell value onto them. Their callers need
positional access (`ChunkGroupInfo::chunk_group_keys` is indexed like
`chunk_groups`), conversions from the
`FxIndexMap`/`FxIndexSet`/`BTreeMap` values they build, and borrowed
`Equivalent` lookup keys (`CompileTimeDefines`).
## How?
The new trait only adds methods for storages that keep insertion order,
so unordered storages and the existing `BackingMapStorage` contract are
unchanged.
Tests cover lists and maps (5 and 50 entries), order-preserving removal
shifting later indices, appended inserts, indices staying the same
across the list → map conversion, and conversions at the 0 / 5 / 32 / 33
/ 100 boundaries, `from_unique_iterator` with exact, understated and
overstated size hints, `Equivalent` lookups on every lookup method, and
`keys`. `cargo test` and `cargo miri test` for `auto-hash-map`, clippy
and rustdoc with `-D warnings`.
<!-- NEXT_JS_LLM -->
<!-- fleet 14d61f44-d6a1-4adf-839c-9584f32828c2 -->
---------
Co-authored-by: vercel-fleet-prod[bot] <318278635+vercel-fleet-prod[bot]@users.noreply.github.com>
Co-authored-by: Tobias Koppers <1365881+sokra@users.noreply.github.com>