# ds-ext
**Archived — no longer maintained.** New projects should use standard collections
or the alternatives below. The full library remains available for existing users;
archival does not remove its source or change already published releases.
[![Crates.io][crates-badge]][crates-url]
[![Docs.rs][docs-badge]][docs-url]
[crates-badge]: https://img.shields.io/crates/v/ds-ext.svg
[crates-url]: https://crates.io/crates/ds-ext
[docs-badge]: https://docs.rs/ds-ext/badge.svg
[docs-url]: https://docs.rs/ds-ext/
## Why archive it?
Rust's standard collections now cover TinyChain's ordered transaction indexes.
TinyChain uses `BTreeMap` and `BTreeSet` for those indexes, and freqfs owns a small
private structure for its cache-specific priority policy. No active TinyChain
crate depends on ds-ext. Maintaining a separate general-purpose collection
library is no longer justified by this project's needs.
This is a maintenance decision, not a claim that another implementation is
universally faster. The existing standalone collections and optional integrations
are retained, including the correctness fixes described below.
## Alternatives
Choose by the ordering and ownership behavior your application needs.
| Unordered lookup | Standard [`HashMap` and `HashSet`](https://doc.rust-lang.org/std/collections/) | Iteration is not in key order. |
| Key ordering, ranges, and first/last entries | Standard [`BTreeMap` and `BTreeSet`](https://doc.rust-lang.org/std/collections/) | Exact lookup uses tree comparisons rather than hashing. |
| Comparison-based search over sorted data | Slice [`binary_search_by`](https://doc.rust-lang.org/std/primitive.slice.html#method.binary_search_by) or [`partition_point`](https://doc.rust-lang.org/std/primitive.slice.html#method.partition_point) | Handle incomparable edges explicitly; use a lower-bound partition when the first equal item matters. |
| Insertion order and positional access | [`IndexMap` and `IndexSet`](https://docs.rs/indexmap/latest/indexmap/) | Swap removal changes survivor order; order-preserving shift removal is linear. |
| Linked ordering or an LRU cache | [`hashlink`](https://docs.rs/hashlink/latest/hashlink/) | Front/back movement and LRU are different policies from one-position promotion. |
| A complete concurrent cache | [`Moka`](https://docs.rs/moka/latest/moka/) | Its default TinyLFU policy combines frequency-based admission and LRU eviction; it does not reproduce ds-ext's promotion policy. |
These are not universal drop-in replacements. Check insertion/replacement order,
removal and drain behavior, and any persisted hashes or codec representations
before migrating. A replacement's hashing or serialization support does not by
itself guarantee the same bytes or digest.
## Retained functionality
- [`LinkedHashMap`](src/queue.rs): front insertion/replacement, one-position promotion, arbitrary
swapping, removal, cloning, and borrowed/owned double-ended iteration.
- [`OrdHashMap`](src/map.rs) and [`OrdHashSet`](src/set.rs): key ordering, exact lookup, comparison-based
bisection, mutation, partial drains, owned iteration, and size accounting.
- Optional integrations: `hash` enables `async-hash`; `stream` enables `destream`;
`serialize` enables Serde; `all` enables all three. Hash support follows
`async-hash` trait bounds; borrowed hashing requires borrowed element support.
### Cache priority ordering
The linked map remains a reusable cache-ordering primitive. A hit is represented
by an explicit `bump`: ordinary `get` does not change priority. A bump exchanges
an entry with its immediate predecessor; removal preserves survivor order.
This is neither exact LFU nor LRU, and the map does not manage cache capacity.
A caller can consume candidates from the back to implement its eviction policy.
```rust
use ds_ext::LinkedHashMap;
let mut priority = LinkedHashMap::new();
for key in 1..=3 {
priority.insert(key, key * 10);
}
assert_eq!(priority.keys().copied().collect::<Vec<_>>(), vec![3, 2, 1]);
assert!(priority.bump(&1));
assert_eq!(priority.keys().copied().collect::<Vec<_>>(), vec![3, 1, 2]);
assert_eq!(priority.iter().next_back(), Some((&2, &20)));
assert_eq!(priority.remove(&1), Some(10));
assert_eq!(priority.keys().copied().collect::<Vec<_>>(), vec![3, 2]);
```
Borrowed cursors do not retain keys. Shared key links remain owned so keys need
not implement `Clone` unless the map itself is cloned. The current implementation
requires Rust 1.86 or newer for disjoint mutable map access.
### Ordered lookup
Bisection compares the target with each stored key. Defined results must run
from `Greater` through `Equal` to `Less`; incomparable keys may occur only at the
edges. Search visits those excluded edges, then performs a logarithmic lower-bound
search. An incomparable interior key encountered by the search is an invariant
violation, not a missing match.
```rust
use ds_ext::{OrdHashMap, OrdHashSet};
let set = OrdHashSet::from_iter([3, 1, 2]);
assert_eq!(set.iter().copied().collect::<Vec<_>>(), vec![1, 2, 3]);
assert_eq!(map.bisect(|key| 2.partial_cmp(key)), Some(&20));
```
Unit-test implementations live under `tests/unit/`, included through private
conditional module declarations. Existing published versions are unchanged by
these local API and correctness updates.