#hash-table #composable-indexes #index #zip #operation #mapping #person #premap

composable-indexes

In-memory collections with composable indexes

5 unstable releases

Uses new Rust 2024

new 0.4.1 May 7, 2025
0.4.0 May 5, 2025
0.3.0 Apr 12, 2025
0.1.1 Apr 8, 2025
0.1.0 Apr 7, 2025

#2 in #hash-table

Download history 107/week @ 2025-04-02 209/week @ 2025-04-09 22/week @ 2025-04-16 93/week @ 2025-04-30

392 downloads per month

Apache-2.0

44KB
1K SLoC

A library for in-memory collections with flexible and composable indexes.

This crate provides a framework for building collections with multiple indexes that can be combined and composed. Key features include:

  • Built-in indexes for common use cases (BTree, HashTable)
  • Composable index combinators (grouping, filtering, mapping)
  • Aggregation indexes for statistical operations
  • Safe and efficient index maintenance as collection changes

Example

use composable_indexes::{Collection, index};

// A struct representing a person
struct Person { name: String, age: u32, occupation: String }

// Create a collection indexed by age using premap
let mut collection = Collection::<Person, _>::new(
  index::zip!(
    index::premap(|p: &Person| p.age, index::btree()),
    index::premap(|p: &Person| p.occupation.clone(), index::hashtable()),
  )
);

// insert & update collection
let alice = collection.insert(Person { name: "Alice".to_string(), age: 30, occupation: "Engineer".to_string() });
collection.insert(Person { name: "Bob".to_string(), age: 25, occupation: "Designer".to_string() });
collection.adjust_mut(alice, |p| { p.age = 31; });
// ...

let q = collection.query();

// Query oldest person
let _youngest = q.0.max_one();

// Query the number of unique occupations
let _occupation_count = q.1.count_distinct();

Dependencies

~295–790KB
~18K SLoC