Compare commits
2 Commits
08c16eb17f
...
1e232f50f5
| Author | SHA1 | Date | |
|---|---|---|---|
| 1e232f50f5 | |||
| 183f098911 |
36
src/lib.rs
36
src/lib.rs
@@ -55,25 +55,23 @@
|
|||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// fn main() {
|
|
||||||
///
|
///
|
||||||
/// let table = vec![MyPair{ a: 10, b:34}, MyPair{ a: 1, b:56}, MyPair{ a: 2, b:23}];
|
/// let table = vec![MyPair{ a: 10, b:34}, MyPair{ a: 1, b:56}, MyPair{ a: 2, b:23}];
|
||||||
///
|
///
|
||||||
/// // Example without using an actual index crate, we will simply use
|
/// // Example without using an actual index crate, we will simply use
|
||||||
/// // the Record<K> trait to sort the array of pairs.
|
/// // the Record<K> trait to sort the array of pairs.
|
||||||
/// let mut lex_sort = table.clone();
|
/// let mut lex_sort = table.clone();
|
||||||
/// lex_sort.sort_unstable_by_key(|e| {let k: String = e.key(); k});
|
/// lex_sort.sort_unstable_by_key(|e| {let k: String = e.key(); k});
|
||||||
///
|
///
|
||||||
/// let mut num_sort = table.clone();
|
/// let mut num_sort = table.clone();
|
||||||
/// num_sort.sort_unstable_by_key(|e| {let k: i64 = e.key(); k});
|
/// num_sort.sort_unstable_by_key(|e| {let k: i64 = e.key(); k});
|
||||||
///
|
///
|
||||||
/// assert_eq!(format!("unsorted {:?}", table),
|
/// assert_eq!(format!("unsorted {:?}", table),
|
||||||
/// "unsorted [MyPair { a: 10, b: 34 }, MyPair { a: 1, b: 56 }, MyPair { a: 2, b: 23 }]");
|
/// "unsorted [MyPair { a: 10, b: 34 }, MyPair { a: 1, b: 56 }, MyPair { a: 2, b: 23 }]");
|
||||||
/// assert_eq!(format!("lex sort {:?}", lex_sort),
|
/// assert_eq!(format!("lex sort {:?}", lex_sort),
|
||||||
/// "lex sort [MyPair { a: 1, b: 56 }, MyPair { a: 10, b: 34 }, MyPair { a: 2, b: 23 }]");
|
/// "lex sort [MyPair { a: 1, b: 56 }, MyPair { a: 10, b: 34 }, MyPair { a: 2, b: 23 }]");
|
||||||
/// assert_eq!(format!("num sort {:?}", num_sort),
|
/// assert_eq!(format!("num sort {:?}", num_sort),
|
||||||
/// "num sort [MyPair { a: 1, b: 56 }, MyPair { a: 2, b: 23 }, MyPair { a: 10, b: 34 }]");
|
/// "num sort [MyPair { a: 1, b: 56 }, MyPair { a: 2, b: 23 }, MyPair { a: 10, b: 34 }]");
|
||||||
/// }
|
|
||||||
/// ```
|
/// ```
|
||||||
pub trait Record<K> {
|
pub trait Record<K> {
|
||||||
/// Extract the key from the record.
|
/// Extract the key from the record.
|
||||||
@@ -104,14 +102,14 @@ pub trait RecordFields<F> {
|
|||||||
// semantic order
|
// semantic order
|
||||||
pub trait Indexed<R, K> {
|
pub trait Indexed<R, K> {
|
||||||
/// Retrieve all records matching the key.
|
/// Retrieve all records matching the key.
|
||||||
fn find(&self, key: &K) -> Vec<&R>;
|
fn find<'i>(&'i self, key: &K) -> Box<dyn Iterator<Item = &R> + 'i>;
|
||||||
|
|
||||||
/// Retrieve all records matching in the key range defined by
|
/// Retrieve all records matching in the key range defined by
|
||||||
/// `start` and `end`.
|
/// `start` and `end`.
|
||||||
///
|
///
|
||||||
/// * `start` is included
|
/// * `start` is included
|
||||||
// TODO: TBC for `end`
|
// TODO: TBC for `end`
|
||||||
fn find_range(&self, start: &K, end: &K) -> Vec<&R>;
|
fn find_range<'i>(&'i self, start: &K, end: &K) -> Box<dyn Iterator<Item = &R> + 'i>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Methods provided by destructuring indices.
|
/// Methods provided by destructuring indices.
|
||||||
@@ -123,12 +121,12 @@ pub trait Indexed<R, K> {
|
|||||||
/// * `K`: Type of the keys
|
/// * `K`: Type of the keys
|
||||||
pub trait IndexedDestructured<F, K> {
|
pub trait IndexedDestructured<F, K> {
|
||||||
/// Retrieve all records matching the key.
|
/// Retrieve all records matching the key.
|
||||||
fn find(&self, key: &K) -> Vec<&F>;
|
fn find<'i>(&'i self, key: &K) -> Box<dyn Iterator<Item = &F> + 'i>;
|
||||||
|
|
||||||
/// Retrieve all records matching in the key range defined by
|
/// Retrieve all records matching in the key range defined by
|
||||||
/// `start` and `end`.
|
/// `start` and `end`.
|
||||||
///
|
///
|
||||||
/// * `start` is included
|
/// * `start` is included
|
||||||
// TODO: TBC for `end`
|
// TODO: TBC for `end`
|
||||||
fn find_range(&self, start: &K, end: &K) -> Vec<(K, &F)>;
|
fn find_range<'i>(&'i self, start: &K, end: &K) -> Box<dyn Iterator<Item = (K, &F)> + 'i>;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user