2021-01-12 23:09:46 +01:00
|
|
|
|
2021-01-12 23:13:27 +01:00
|
|
|
pub mod map_item;
|
2021-01-16 13:57:06 +01:00
|
|
|
pub mod map_key;
|
2021-08-27 22:31:25 +02:00
|
|
|
pub mod buffer;
|
2021-01-12 23:13:27 +01:00
|
|
|
|
2021-01-06 21:35:46 +01:00
|
|
|
use {
|
|
|
|
std::{
|
2021-03-30 22:47:05 +02:00
|
|
|
sync::Arc,
|
2021-11-07 07:16:33 +01:00
|
|
|
ops::{Deref, RangeInclusive},
|
2021-01-06 21:35:46 +01:00
|
|
|
},
|
2021-03-30 22:47:05 +02:00
|
|
|
std::sync::RwLock,
|
2021-01-06 21:35:46 +01:00
|
|
|
crate::core::View
|
|
|
|
};
|
|
|
|
|
|
|
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
|
|
|
|
2021-11-07 07:16:33 +01:00
|
|
|
#[derive(Clone)]
|
|
|
|
pub enum IndexArea<Key> {
|
|
|
|
Empty,
|
|
|
|
Full,
|
|
|
|
Set(Vec<Key>),
|
|
|
|
Range(RangeInclusive<Key>),
|
|
|
|
//Procedural(Arc<dyn Fn() -> Box<dyn Iterator<Item = Key>>>)
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<Key> IndexArea<Key> {
|
|
|
|
pub fn map<T>(&self, f: impl Fn(&Key) -> T) -> IndexArea<T> {
|
|
|
|
match self {
|
|
|
|
IndexArea::Empty => IndexArea::Empty,
|
|
|
|
IndexArea::Full => IndexArea::Full,
|
|
|
|
IndexArea::Set(v) => IndexArea::Set(v.iter().map(&f).collect()),
|
|
|
|
IndexArea::Range(r) => IndexArea::Range(f(&r.start()) ..= f(&r.end()))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait IndexView<Key> : View<Msg = IndexArea<Key>>
|
2021-05-22 01:33:58 +02:00
|
|
|
where Key: Send + Sync {
|
2021-01-06 21:35:46 +01:00
|
|
|
type Item;
|
|
|
|
|
2021-01-16 20:19:52 +01:00
|
|
|
fn get(&self, key: &Key) -> Option<Self::Item>;
|
2021-01-06 21:35:46 +01:00
|
|
|
|
2021-11-07 07:16:33 +01:00
|
|
|
fn area(&self) -> IndexArea<Key> {
|
|
|
|
IndexArea::Full
|
2021-01-06 21:35:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
|
|
|
|
2021-05-22 01:33:58 +02:00
|
|
|
impl<Key, V> IndexView<Key> for RwLock<V>
|
|
|
|
where Key: Send + Sync,
|
|
|
|
V: IndexView<Key> + ?Sized
|
|
|
|
{
|
2021-01-06 21:35:46 +01:00
|
|
|
type Item = V::Item;
|
|
|
|
|
2021-01-16 20:19:52 +01:00
|
|
|
fn get(&self, key: &Key) -> Option<Self::Item> {
|
2021-01-06 21:35:46 +01:00
|
|
|
self.read().unwrap().get(key)
|
|
|
|
}
|
|
|
|
|
2021-11-07 07:16:33 +01:00
|
|
|
fn area(&self) -> IndexArea<Key> {
|
2021-01-16 13:57:06 +01:00
|
|
|
self.read().unwrap().area()
|
2021-01-06 21:35:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-22 01:33:58 +02:00
|
|
|
impl<Key, V> IndexView<Key> for Arc<V>
|
|
|
|
where Key: Send + Sync,
|
|
|
|
V: IndexView<Key> + ?Sized
|
|
|
|
{
|
2021-01-06 21:35:46 +01:00
|
|
|
type Item = V::Item;
|
|
|
|
|
2021-01-16 20:19:52 +01:00
|
|
|
fn get(&self, key: &Key) -> Option<Self::Item> {
|
2021-01-06 21:35:46 +01:00
|
|
|
self.deref().get(key)
|
|
|
|
}
|
2021-01-16 13:57:06 +01:00
|
|
|
|
2021-11-07 07:16:33 +01:00
|
|
|
fn area(&self) -> IndexArea<Key> {
|
2021-01-16 13:57:06 +01:00
|
|
|
self.deref().area()
|
2021-01-06 21:35:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-22 01:33:58 +02:00
|
|
|
impl<Key, V> IndexView<Key> for Option<V>
|
|
|
|
where Key: Send + Sync,
|
|
|
|
V: IndexView<Key>
|
|
|
|
{
|
2021-01-19 22:54:50 +01:00
|
|
|
type Item = V::Item;
|
|
|
|
|
|
|
|
fn get(&self, key: &Key) -> Option<Self::Item> {
|
2021-01-22 14:56:56 +01:00
|
|
|
self.as_ref()?.get(key)
|
2021-01-19 22:54:50 +01:00
|
|
|
}
|
|
|
|
|
2021-11-07 07:16:33 +01:00
|
|
|
fn area(&self) -> IndexArea<Key> {
|
2021-01-19 22:54:50 +01:00
|
|
|
if let Some(v) = self.as_ref() {
|
|
|
|
v.area()
|
|
|
|
} else {
|
2021-11-07 07:16:33 +01:00
|
|
|
IndexArea::Empty
|
2021-01-19 22:54:50 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-06 21:35:46 +01:00
|
|
|
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
2021-11-07 07:16:33 +01:00
|
|
|
/*
|
2021-01-06 21:35:46 +01:00
|
|
|
pub trait ImplIndexView : Send + Sync {
|
2021-05-22 01:33:58 +02:00
|
|
|
type Key : Send + Sync;
|
2021-01-06 21:35:46 +01:00
|
|
|
type Value;
|
|
|
|
|
2021-01-16 20:19:52 +01:00
|
|
|
fn get(&self, key: &Self::Key) -> Option<Self::Value>;
|
2021-01-16 13:57:06 +01:00
|
|
|
fn area(&self) -> Option<Vec<Self::Key>> {
|
2021-01-06 21:35:46 +01:00
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<V: ImplIndexView> View for V {
|
|
|
|
type Msg = V::Key;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<V: ImplIndexView> IndexView<V::Key> for V {
|
|
|
|
type Item = V::Value;
|
|
|
|
|
2021-01-16 20:19:52 +01:00
|
|
|
fn get(&self, key: &V::Key) -> Option<Self::Item> {
|
2021-01-06 21:35:46 +01:00
|
|
|
(self as &V).get(key)
|
|
|
|
}
|
|
|
|
|
2021-01-16 13:57:06 +01:00
|
|
|
fn area(&self) -> Option<Vec<V::Key>> {
|
|
|
|
(self as &V).area()
|
2021-01-06 21:35:46 +01:00
|
|
|
}
|
|
|
|
}
|
2021-11-07 07:16:33 +01:00
|
|
|
*/
|