Compare commits
2 Commits
41f8aa368b
...
8358570414
| Author | SHA1 | Date | |
|---|---|---|---|
| 8358570414 | |||
| 0d483b3f9b |
@@ -9,6 +9,22 @@ use ironsea_index::RecordFields;
|
|||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
|
/// Implementation of [`ironsea_index`]::[`IndexedDestructured`].
|
||||||
|
///
|
||||||
|
/// The index is backed by a [`std`]`::`[`collections`]`::`[`HashMap`].
|
||||||
|
///
|
||||||
|
/// An ordered [`std`]`::`[`vec`]`::`[`Vec`] of keys is maintained, in
|
||||||
|
/// order to satisfy range queries.
|
||||||
|
///
|
||||||
|
/// [`ironsea_index`]: https://epfl-dias.github.io/ironsea_index/ironsea_index/index.html
|
||||||
|
/// [`IndexedDestructured`]: https://epfl-dias.github.io/ironsea_index/ironsea_index/trait.IndexedDestructured.html
|
||||||
|
///
|
||||||
|
/// [`std`]: https://doc.rust-lang.org/std/index.html
|
||||||
|
/// [`collections`]: https://doc.rust-lang.org/std/collections/index.html
|
||||||
|
/// [`HashMap`]: https://doc.rust-lang.org/std/collections/struct.HashMap.html
|
||||||
|
/// [`vec`]: https://doc.rust-lang.org/std/vec/index.html
|
||||||
|
/// [`Vec`]: https://doc.rust-lang.org/std/vec/struct.Vec.html
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct Index<F, K>
|
pub struct Index<F, K>
|
||||||
where
|
where
|
||||||
@@ -22,6 +38,7 @@ impl<F, K> Index<F, K>
|
|||||||
where
|
where
|
||||||
K: Clone + Eq + Hash + PartialEq + Ord,
|
K: Clone + Eq + Hash + PartialEq + Ord,
|
||||||
{
|
{
|
||||||
|
/// Creates a new Index from the provided iterator.
|
||||||
pub fn new<I, R>(iter: I) -> Self
|
pub fn new<I, R>(iter: I) -> Self
|
||||||
where
|
where
|
||||||
I: Iterator<Item = R>,
|
I: Iterator<Item = R>,
|
||||||
@@ -40,11 +57,16 @@ where
|
|||||||
Index { hashmap, keys }
|
Index { hashmap, keys }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return an ordered list of all keys contained in the index.
|
||||||
pub fn keys(&self) -> &Vec<K> {
|
pub fn keys(&self) -> &Vec<K> {
|
||||||
&self.keys
|
&self.keys
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn index(&self, key: &K) -> usize {
|
/// Returns the position within the index of the key.
|
||||||
|
///
|
||||||
|
/// If the key is not found, return the index where it should be
|
||||||
|
/// inserted.
|
||||||
|
fn index(&self, key: &K) -> usize {
|
||||||
match self.keys.binary_search(&key) {
|
match self.keys.binary_search(&key) {
|
||||||
Ok(i) => i,
|
Ok(i) => i,
|
||||||
Err(i) => {
|
Err(i) => {
|
||||||
|
|||||||
@@ -9,6 +9,22 @@ use ironsea_index::Record;
|
|||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
|
||||||
|
/// Implementation of [`ironsea_index`]::[`Indexed`].
|
||||||
|
///
|
||||||
|
/// The index is backed by a [`std`]`::`[`collections`]`::`[`HashMap`].
|
||||||
|
///
|
||||||
|
/// An ordered [`std`]`::`[`vec`]`::`[`Vec`] of keys is maintained, in
|
||||||
|
/// order to satisfy range queries.
|
||||||
|
///
|
||||||
|
/// [`ironsea_index`]: https://epfl-dias.github.io/ironsea_index/ironsea_index/index.html
|
||||||
|
/// [`Indexed`]: https://epfl-dias.github.io/ironsea_index/ironsea_index/trait.Indexed.html
|
||||||
|
///
|
||||||
|
/// [`std`]: https://doc.rust-lang.org/std/index.html
|
||||||
|
/// [`collections`]: https://doc.rust-lang.org/std/collections/index.html
|
||||||
|
/// [`HashMap`]: https://doc.rust-lang.org/std/collections/struct.HashMap.html
|
||||||
|
/// [`vec`]: https://doc.rust-lang.org/std/vec/index.html
|
||||||
|
/// [`Vec`]: https://doc.rust-lang.org/std/vec/struct.Vec.html
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct Index<R, K>
|
pub struct Index<R, K>
|
||||||
where
|
where
|
||||||
@@ -23,6 +39,7 @@ where
|
|||||||
R: Record<K>,
|
R: Record<K>,
|
||||||
K: Clone + Eq + Hash + PartialEq + Ord,
|
K: Clone + Eq + Hash + PartialEq + Ord,
|
||||||
{
|
{
|
||||||
|
/// Creates a new Index from the provided iterator.
|
||||||
pub fn new<I>(iter: I) -> Self
|
pub fn new<I>(iter: I) -> Self
|
||||||
where
|
where
|
||||||
I: Iterator<Item = R>,
|
I: Iterator<Item = R>,
|
||||||
@@ -40,11 +57,16 @@ where
|
|||||||
Index { hashmap, keys }
|
Index { hashmap, keys }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Return an ordered list of all keys contained in the index.
|
||||||
pub fn keys(&self) -> &Vec<K> {
|
pub fn keys(&self) -> &Vec<K> {
|
||||||
&self.keys
|
&self.keys
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn index(&self, key: &K) -> usize {
|
/// Returns the position within the index of the key.
|
||||||
|
///
|
||||||
|
/// If the key is not found, return the index where it should be
|
||||||
|
/// inserted.
|
||||||
|
fn index(&self, key: &K) -> usize {
|
||||||
match self.keys.binary_search(key) {
|
match self.keys.binary_search(key) {
|
||||||
Ok(i) => i,
|
Ok(i) => i,
|
||||||
Err(i) => {
|
Err(i) => {
|
||||||
|
|||||||
23
src/lib.rs
23
src/lib.rs
@@ -1,4 +1,27 @@
|
|||||||
#![forbid(unsafe_code)]
|
#![forbid(unsafe_code)]
|
||||||
|
#![deny(missing_docs)]
|
||||||
|
|
||||||
|
//! # Iron Sea - Index Hash Map
|
||||||
|
//!
|
||||||
|
//! A simple hash map index for the Iron Sea toolkit, based on
|
||||||
|
//! [`std`]`::`[`collections`]`::`[`HashMap`].
|
||||||
|
//!
|
||||||
|
//! [`std`]: https://doc.rust-lang.org/std/index.html
|
||||||
|
//! [`collections`]: https://doc.rust-lang.org/std/collections/index.html
|
||||||
|
//! [`HashMap`]: https://doc.rust-lang.org/std/collections/struct.HashMap.html
|
||||||
|
//!
|
||||||
|
//! ## Iron Sea: Database Toolkit
|
||||||
|
//! **Iron Sea** provides a set of database engine bricks, which can be
|
||||||
|
//! combined and applied on arbitrary data structures.
|
||||||
|
//!
|
||||||
|
//! Unlike a traditional database, it does not assume a specific
|
||||||
|
//! physical structure for the tables nor the records, but relies on the
|
||||||
|
//! developer to provide a set of extractor functions which are used by
|
||||||
|
//! the specific indices provided.
|
||||||
|
//!
|
||||||
|
//! This enables the index implementations to be agnostic from the
|
||||||
|
//! underlying data structure, and re-used.
|
||||||
|
//!
|
||||||
|
|
||||||
mod destructured;
|
mod destructured;
|
||||||
mod full_record;
|
mod full_record;
|
||||||
|
|||||||
Reference in New Issue
Block a user