14 releases (5 breaking)

0.6.1 Dec 28, 2023
0.6.0 Oct 13, 2023
0.5.0 Oct 13, 2023
0.4.2 Oct 12, 2023
0.1.1 Aug 31, 2023

#536 in Data structures

Download history 8/week @ 2023-12-19 21/week @ 2023-12-26 9/week @ 2024-01-02 12/week @ 2024-01-09 9/week @ 2024-01-16 1/week @ 2024-01-23 8/week @ 2024-01-30 17/week @ 2024-02-06 30/week @ 2024-02-13 69/week @ 2024-02-20 43/week @ 2024-02-27 30/week @ 2024-03-05 89/week @ 2024-03-12 43/week @ 2024-03-19 11/week @ 2024-03-26 26/week @ 2024-04-02

171 downloads per month
Used in 3 crates

MIT/Apache

59KB
1.5K SLoC

Indexical: Human-Friendly Indexed Collections

Indexical is a library for conveniently and efficiently working with indexed collections of objects. "Indexed" means that the domain of objects is finite, and you can assign a numeric index to each object. This enables the use of efficient data structures like bit-sets.

Indexical is a layer on top of existing bit-set libraries like bitvec and rustc_index::bit_set. Those data structures only "understand" raw indexes, not the objects represented by the index. Indexical provides utilities for converting between the object domain and the index domain.

Example

use indexical::{IndexedDomain, IndexedValue, bitset::bitvec::IndexSet};
use std::rc::Rc;

// 1. Define a custom type.
#[derive(PartialEq, Eq, Clone, Hash)]
pub struct MyString(String);

// 2. Define a new index for your custom type.
indexical::define_index_type! {
    pub struct StringIndex for MyString = u32;
}

// 3. Create an immutable indexed domain from a collection of objects.
// By default this is Rc-wrapped, but you can also use Arc or &-refs.
let domain = Rc::new(IndexedDomain::from_iter([
    MyString(String::from("Hello")), MyString(String::from("world"))
]));

// 4. Now you can make a set! Notice how you can pass either a `MyString`
// or a `StringIndex` to `set.insert(..)` and `set.contains(..)`.
let mut set = IndexSet::new(&domain);
set.insert(MyString(String::from("Hello")));
set.insert(StringIndex::from_usize(1));
assert!(set.contains(&MyString(String::from("world"))));

Dependencies

~2MB
~40K SLoC