Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/willcrichton/indexical
Human-friendly indexed collections
https://github.com/willcrichton/indexical
Last synced: 2 months ago
JSON representation
Human-friendly indexed collections
- Host: GitHub
- URL: https://github.com/willcrichton/indexical
- Owner: willcrichton
- License: apache-2.0
- Created: 2023-08-31T05:41:13.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-12-28T21:03:58.000Z (12 months ago)
- Last Synced: 2024-10-08T09:43:37.810Z (3 months ago)
- Language: Rust
- Homepage: https://docs.rs/indexical
- Size: 59.6 KB
- Stars: 51
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# 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`](https://github.com/ferrilab/bitvec)
and [`rustc_index::bit_set`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_index/bit_set/index.html).
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
```rust
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"))));
```