ds-ext 0.5.0

Extensions to standard Rust data structures which provide additional capabilities
Documentation

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 Docs.rs

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.

Need Alternative Migration consideration
Unordered lookup Standard HashMap and HashSet Iteration is not in key order.
Key ordering, ranges, and first/last entries Standard BTreeMap and BTreeSet Exact lookup uses tree comparisons rather than hashing.
Comparison-based search over sorted data Slice binary_search_by or 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 Swap removal changes survivor order; order-preserving shift removal is linear.
Linked ordering or an LRU cache hashlink Front/back movement and LRU are different policies from one-position promotion.
A complete concurrent cache 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: front insertion/replacement, one-position promotion, arbitrary swapping, removal, cloning, and borrowed/owned double-ended iteration.
  • OrdHashMap and OrdHashSet: 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.

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.

use ds_ext::{OrdHashMap, OrdHashSet};

let set = OrdHashSet::from_iter([3, 1, 2]);
assert_eq!(set.iter().copied().collect::<Vec<_>>(), vec![1, 2, 3]);

let map = OrdHashMap::from_iter(set.into_iter().map(|key| (key, key * 10)));
assert_eq!(map.get(&2), Some(&20));
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.