use crate::leaf15::LeafNode15;
use crate::nodeversion::LockGuard;
use crate::policy::LeafPolicy;
use super::{LocalGuard, MassTreeGeneric, TreeAllocator};
pub trait InsertStrategy<P: LeafPolicy, A: TreeAllocator<P>> {
type Input;
type OldValue;
fn into_output(input: Self::Input) -> P::Output;
fn update_existing(
tree: &MassTreeGeneric<P, A>,
leaf: &LeafNode15<P>,
lock: &mut LockGuard<'_>,
slot: usize,
input: &Self::Input,
guard: &LocalGuard<'_>,
) -> Self::OldValue;
}
pub struct GenericInsert;
impl<P: LeafPolicy, A: TreeAllocator<P>> InsertStrategy<P, A> for GenericInsert {
type Input = P::Output;
type OldValue = P::Output;
#[inline(always)]
fn into_output(input: P::Output) -> P::Output {
input
}
#[inline(always)]
fn update_existing(
tree: &MassTreeGeneric<P, A>,
leaf: &LeafNode15<P>,
lock: &mut LockGuard<'_>,
slot: usize,
input: &P::Output,
guard: &LocalGuard<'_>,
) -> P::Output {
tree.update_existing_value(leaf, lock, slot, input, guard)
}
}
pub struct WriteThroughInsert;
impl<P: LeafPolicy, A: TreeAllocator<P>> InsertStrategy<P, A> for WriteThroughInsert {
type Input = P::Value;
type OldValue = P::Value;
#[inline(always)]
fn into_output(input: P::Value) -> P::Output {
P::into_output(input)
}
#[inline(always)]
fn update_existing(
tree: &MassTreeGeneric<P, A>,
leaf: &LeafNode15<P>,
lock: &mut LockGuard<'_>,
slot: usize,
input: &P::Value,
_guard: &LocalGuard<'_>,
) -> P::Value {
tree.update_existing_value_write_through(leaf, lock, slot, input)
}
}