Crate composable_indexes

Crate composable_indexes 

Source
Expand description

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::btree()),
  )
);

// 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_by_key_mut(alice, |p| { p.age = 31; });
// ...

// Query oldest person
let _oldest = collection.query(|ix| ix._1().max_one());

// Query the number of unique occupations
let _occupation_count = collection.query(|ix| ix._2().count_distinct());

Re-exports§

pub use core::Collection;
pub use core::Key;

Modules§

aggregation
Module providing aggregation indexes for computing aggregate values over collections. Includes common aggregations like count, sum, and mean.
core
index
Module providing various index implementations and combinators. Includes basic indexes like BTree and HashTable, as well as combinators for transforming, grouping, and filtering indexes.

Derive Macros§

Index
Derive macro for automatically implementing the Index trait.