Simplify cht impls

next
Sayan Nandan 1 year ago
parent 05d93d2102
commit 60157e110b
No known key found for this signature in database
GPG Key ID: 42EEDF4AE9D96B54

@ -90,7 +90,7 @@ pub enum DatabaseError {
NeedLock,
/// expected a full entity, but found a single implicit entity
ExpectedEntity,
// ddl: create space
// ddl
/// unknown property or bad type for property
DdlSpaceBadProperty,
/// the space already exists

@ -43,6 +43,7 @@ use {
pub type IndexSTSeqCns<K, V> = stord::IndexSTSeqDll<K, V, stord::config::ConservativeConfig<K, V>>;
pub type IndexSTSeqLib<K, V> = stord::IndexSTSeqDll<K, V, stord::config::LiberalConfig<K, V>>;
pub type IndexMTRC<K, V> = mtchm::imp::ChmArc<K, V, mtchm::meta::DefConfig>;
pub type IndexMTRaw<E> = mtchm::RawTree<E, mtchm::meta::DefConfig>;
pub type IndexMTCp<K, V> = mtchm::imp::ChmCopy<K, V, mtchm::meta::DefConfig>;
pub type IndexST<K, V, S = std::collections::hash_map::RandomState> =
std::collections::hash_map::HashMap<K, V, S>;
@ -100,7 +101,7 @@ pub struct DummyMetrics;
/// The base spec for any index. Iterators have meaningless order, and that is intentional and oftentimes
/// consequential. For more specialized impls, use the [`STIndex`], [`MTIndex`] or [`STIndexSeq`] traits
pub trait IndexBaseSpec<K: ?Sized, V: ?Sized>: Sized {
pub trait IndexBaseSpec: Sized {
/// Index supports prealloc?
const PREALLOC: bool;
#[cfg(debug_assertions)]
@ -126,7 +127,7 @@ pub trait IndexBaseSpec<K: ?Sized, V: ?Sized>: Sized {
}
/// An unordered MTIndex
pub trait MTIndex<K, V>: IndexBaseSpec<K, V> {
pub trait MTIndex<K, V>: IndexBaseSpec {
type IterKV<'t, 'g, 'v>: Iterator<Item = (&'v K, &'v V)>
where
'g: 't + 'v,
@ -202,7 +203,7 @@ pub trait MTIndex<K, V>: IndexBaseSpec<K, V> {
}
/// An unordered STIndex
pub trait STIndex<K: ?Sized, V>: IndexBaseSpec<K, V> {
pub trait STIndex<K: ?Sized, V>: IndexBaseSpec {
/// An iterator over the keys and values
type IterKV<'a>: Iterator<Item = (&'a K, &'a V)>
where

@ -34,261 +34,135 @@ use {
RawTree,
},
crate::engine::{
idx::{meta::Comparable, AsKey, AsKeyClone, AsValue, AsValueClone, IndexBaseSpec, MTIndex},
sync::atm::{upin, Guard},
idx::{meta::Comparable, AsKeyClone, AsValue, AsValueClone, IndexBaseSpec, MTIndex},
sync::atm::Guard,
},
std::sync::Arc,
};
#[inline(always)]
fn arc<K, V>(k: K, v: V) -> Arc<(K, V)> {
Arc::new((k, v))
}
pub type ChmArc<K, V, C> = RawTree<Arc<(K, V)>, C>;
pub type Raw<E, C> = RawTree<E, C>;
pub type ChmArc<K, V, C> = Raw<Arc<(K, V)>, C>;
pub type ChmCopy<K, V, C> = Raw<(K, V), C>;
impl<K, V, C> IndexBaseSpec<K, V> for ChmArc<K, V, C>
where
C: Config,
{
impl<E, C: Config> IndexBaseSpec for Raw<E, C> {
const PREALLOC: bool = false;
#[cfg(debug_assertions)]
type Metrics = CHTRuntimeLog;
fn idx_init() -> Self {
ChmArc::new()
Self::new()
}
fn idx_init_with(s: Self) -> Self {
s
}
#[cfg(debug_assertions)]
fn idx_metrics(&self) -> &Self::Metrics {
&self.m
}
}
impl<K, V, C> MTIndex<K, V> for ChmArc<K, V, C>
where
C: Config,
K: AsKey,
V: AsValue,
{
type IterKV<'t, 'g, 'v> = IterKV<'t, 'g, 'v, Arc<(K, V)>, C>
impl<E: TreeElement, C: Config> MTIndex<E::Key, E::Value> for Raw<E, C> {
type IterKV<'t, 'g, 'v> = IterKV<'t, 'g, 'v, E, C>
where
'g: 't + 'v,
't: 'v,
K: 'v,
V: 'v,
E::Key: 'v,
E::Value: 'v,
Self: 't;
type IterKey<'t, 'g, 'v> = IterKey<'t, 'g, 'v, Arc<(K, V)>, C>
type IterKey<'t, 'g, 'v> = IterKey<'t, 'g, 'v, E, C>
where
'g: 't + 'v,
't: 'v,
K: 'v,
E::Key: 'v,
Self: 't;
type IterVal<'t, 'g, 'v> = IterVal<'t, 'g, 'v, Arc<(K, V)>, C>
type IterVal<'t, 'g, 'v> = IterVal<'t, 'g, 'v, E, C>
where
'g: 't + 'v,
't: 'v,
V: 'v,
E::Value: 'v,
Self: 't;
fn mt_clear(&self, g: &Guard) {
self.nontransactional_clear(g)
}
fn mt_insert(&self, key: K, val: V, g: &Guard) -> bool {
self.patch(VanillaInsert(arc(key, val)), g)
}
fn mt_upsert(&self, key: K, val: V, g: &Guard) {
self.patch(VanillaUpsert(arc(key, val)), g)
}
fn mt_contains<Q>(&self, key: &Q, g: &Guard) -> bool
where
Q: ?Sized + Comparable<K>,
{
self.contains_key(key, g)
}
fn mt_get<'t, 'g, 'v, Q>(&'t self, key: &Q, g: &'g Guard) -> Option<&'v V>
where
Q: ?Sized + Comparable<K>,
't: 'v,
'g: 't + 'v,
{
self.get(key, g)
}
fn mt_get_cloned<Q>(&self, key: &Q, g: &Guard) -> Option<V>
where
Q: ?Sized + Comparable<K>,
V: AsValueClone,
{
self.get(key, g).cloned()
}
fn mt_update(&self, key: K, val: V, g: &Guard) -> bool {
self.patch(VanillaUpdate(arc(key, val)), g)
}
fn mt_update_return<'t, 'g, 'v>(&'t self, key: K, val: V, g: &'g Guard) -> Option<&'v V>
fn mt_insert(&self, key: E::Key, val: E::Value, g: &Guard) -> bool
where
't: 'v,
'g: 't + 'v,
E::Value: AsValue,
{
self.patch(VanillaUpdateRet(arc(key, val)), g)
self.patch(VanillaInsert(E::new(key, val)), g)
}
fn mt_delete<Q>(&self, key: &Q, g: &Guard) -> bool
fn mt_upsert(&self, key: E::Key, val: E::Value, g: &Guard)
where
Q: ?Sized + Comparable<K>,
E::Value: AsValue,
{
self.remove(key, g)
}
fn mt_delete_return<'t, 'g, 'v, Q>(&'t self, key: &Q, g: &'g Guard) -> Option<&'v V>
where
Q: ?Sized + Comparable<K>,
't: 'v,
'g: 't + 'v,
{
self.remove_return(key, g)
}
}
pub type ChmCopy<K, V, C> = RawTree<(K, V), C>;
impl<K, V, C> IndexBaseSpec<K, V> for ChmCopy<K, V, C>
where
C: Config,
{
const PREALLOC: bool = false;
#[cfg(debug_assertions)]
type Metrics = CHTRuntimeLog;
fn idx_init() -> Self {
ChmCopy::new()
}
fn idx_init_with(s: Self) -> Self {
s
}
#[cfg(debug_assertions)]
fn idx_metrics(&self) -> &Self::Metrics {
&self.m
}
}
impl<K, V, C> MTIndex<K, V> for ChmCopy<K, V, C>
where
C: Config,
K: AsKeyClone,
V: AsValueClone,
{
type IterKV<'t, 'g, 'v> = IterKV<'t, 'g, 'v, (K, V), C>
where
'g: 't + 'v,
't: 'v,
K: 'v,
V: 'v,
Self: 't;
type IterKey<'t, 'g, 'v> = IterKey<'t, 'g, 'v, (K, V), C>
where
'g: 't + 'v,
't: 'v,
K: 'v,
Self: 't;
type IterVal<'t, 'g, 'v> = IterVal<'t, 'g, 'v, (K, V), C>
where
'g: 't + 'v,
't: 'v,
V: 'v,
Self: 't;
fn mt_clear(&self, g: &Guard) {
self.nontransactional_clear(g)
}
fn mt_insert(&self, key: K, val: V, g: &Guard) -> bool {
self.patch(VanillaInsert((key, val)), g)
}
fn mt_upsert(&self, key: K, val: V, g: &Guard) {
self.patch(VanillaUpsert((key, val)), g)
self.patch(VanillaUpsert(E::new(key, val)), g)
}
fn mt_contains<Q>(&self, key: &Q, g: &Guard) -> bool
where
Q: ?Sized + Comparable<K>,
Q: ?Sized + Comparable<E::Key>,
{
self.contains_key(key, g)
}
fn mt_get<'t, 'g, 'v, Q>(&'t self, key: &Q, g: &'g Guard) -> Option<&'v V>
fn mt_get<'t, 'g, 'v, Q>(&'t self, key: &Q, g: &'g Guard) -> Option<&'v E::Value>
where
Q: ?Sized + Comparable<K>,
Q: ?Sized + Comparable<E::Key>,
't: 'v,
'g: 't + 'v,
{
self.get(key, g)
}
fn mt_get_cloned<Q>(&self, key: &Q, g: &Guard) -> Option<V>
fn mt_get_cloned<Q>(&self, key: &Q, g: &Guard) -> Option<E::Value>
where
Q: ?Sized + Comparable<K>,
Q: ?Sized + Comparable<E::Key>,
E::Value: AsValueClone,
{
self.get(key, g).cloned()
}
fn mt_update(&self, key: K, val: V, g: &Guard) -> bool {
self.patch(VanillaUpdate((key, val)), g)
fn mt_update(&self, key: E::Key, val: E::Value, g: &Guard) -> bool
where
E::Key: AsKeyClone,
E::Value: AsValue,
{
self.patch(VanillaUpdate(E::new(key, val)), g)
}
fn mt_update_return<'t, 'g, 'v>(&'t self, key: K, val: V, g: &'g Guard) -> Option<&'v V>
fn mt_update_return<'t, 'g, 'v>(
&'t self,
key: E::Key,
val: E::Value,
g: &'g Guard,
) -> Option<&'v E::Value>
where
E::Key: AsKeyClone,
E::Value: AsValue,
't: 'v,
'g: 't + 'v,
{
self.patch(VanillaUpdateRet((key, val)), g)
self.patch(VanillaUpdateRet(E::new(key, val)), g)
}
fn mt_delete<Q>(&self, key: &Q, g: &Guard) -> bool
where
Q: ?Sized + Comparable<K>,
Q: ?Sized + Comparable<E::Key>,
{
self.remove(key, g)
}
fn mt_delete_return<'t, 'g, 'v, Q>(&'t self, key: &Q, g: &'g Guard) -> Option<&'v V>
fn mt_delete_return<'t, 'g, 'v, Q>(&'t self, key: &Q, g: &'g Guard) -> Option<&'v E::Value>
where
Q: ?Sized + Comparable<K>,
Q: ?Sized + Comparable<E::Key>,
't: 'v,
'g: 't + 'v,
{
self.remove_return(key, g)
}
}
impl<T: TreeElement, C: Config> FromIterator<T> for RawTree<T, C> {
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
let g = unsafe {
// UNSAFE(@ohsayan): it's me, hi, I'm the problem, it's me. yeah, Taylor knows it too. it's just us
upin()
};
let t = RawTree::new();
iter.into_iter()
.for_each(|te| assert!(t.patch(VanillaInsert(te), g)));
t
}
}

@ -42,7 +42,7 @@ use {
},
};
impl<K, V, S> IndexBaseSpec<K, V> for StdMap<K, V, S>
impl<K, V, S> IndexBaseSpec for StdMap<K, V, S>
where
S: BuildHasher + Default,
{

@ -536,7 +536,7 @@ impl<K: AsKey, V: AsValue, C: Config<K, V>> FromIterator<(K, V)> for IndexSTSeqD
}
}
impl<K, V, C: Config<K, V>> IndexBaseSpec<K, V> for IndexSTSeqDll<K, V, C> {
impl<K, V, C: Config<K, V>> IndexBaseSpec for IndexSTSeqDll<K, V, C> {
const PREALLOC: bool = true;
#[cfg(debug_assertions)]

@ -51,7 +51,9 @@ pub fn parse_inspect<'a, Qd: QueryData<'a>>(
}
match state.fw_read() {
Token![model] => Entity::parse_from_state_rounded_result(state).map(Statement::InspectModel),
Token![model] => {
Entity::parse_from_state_rounded_result(state).map(Statement::InspectModel)
}
Token![space] if state.cursor_has_ident_rounded() => {
Ok(Statement::InspectSpace(unsafe {
// UNSAFE(@ohsayan): Safe because of the match predicate

@ -436,16 +436,9 @@ mod stmt_insert {
let r = parse_ast_node_full::<InsertStatement>(&x[1..]).unwrap();
let e = InsertStatement::new(
Entity::Full(Ident::from("twitter"), Ident::from("users")),
into_array_nullable![
"sayan",
"Sayan",
"sayan@example.com",
true,
12345,
67890
]
.to_vec()
.into(),
into_array_nullable!["sayan", "Sayan", "sayan@example.com", true, 12345, 67890]
.to_vec()
.into(),
);
assert_eq!(e, r);
}

Loading…
Cancel
Save