more uniform name s

This commit is contained in:
AF 2023-05-30 13:51:26 +00:00
parent 99a00d0170
commit c565f0b6dc
11 changed files with 59 additions and 56 deletions

View File

@ -29,7 +29,7 @@ pub trait BinaryTrees<'a>: 'a + Clone {
fn split(&self, node: &Self::Node) -> Split<'a, Self>;
fn tree_of(&self, node: Self::Node) -> BTWrap<'a, Self, Self::Tree>;
fn resolve(&self, reference: &Self::Reference) -> BTWrap<'a, Self, Self::Node>;
fn equal(&self, rhs: &Self::Reference, lhs: &Self::Reference) -> bool;
fn equal(&self, rl: &Self::Reference, rr: &Self::Reference) -> bool;
fn refer(&self, tree: &Self::Tree) -> Option<Self::Reference>;
fn bind<A: 'a, B: 'a>(
@ -192,8 +192,8 @@ pub trait BinaryTreesAvl<'a>: BinaryTrees<'a> {
key: KeyRc<'a, Self>,
tr: Self::Tree,
) -> BTWrap<'a, Self, Self::Node> {
let (lh, rh) = (self.height(&tl), self.height(&tr));
match (lh.saturating_sub(rh), rh.saturating_sub(lh)) {
let (hl, hr) = (self.height(&tl), self.height(&tr));
match (hl.saturating_sub(hr), hr.saturating_sub(hl)) {
(0, 0) | (0, 1) | (1, 0) => self.join_key_unbalanced(tl, key, tr),
(0, _) => Self::bind(self.assume_node(&tr), move |nr| {
let (trl, trr, kr) = self.split(&nr);
@ -215,8 +215,8 @@ pub trait BinaryTreesAvl<'a>: BinaryTrees<'a> {
}),
(_, 0) => Self::bind(self.assume_node(&tl), move |nl| {
let (tll, tlr, kl) = self.split(&nl);
let (llh, lrh) = (self.height(&tll), self.height(&tlr));
if llh < lrh {
let (hll, hlr) = (self.height(&tll), self.height(&tlr));
if hll < hlr {
Self::bind(self.assume_node(&tlr), move |nlr| {
let (tlrl, tlrr, klr) = self.split(&nlr);
Self::T::bind2(

View File

@ -29,8 +29,8 @@ impl<A: Display> Display for AvlN<A> {
#[cfg(test)]
impl<A> AvlN<A> {
fn balanced(&self) -> bool {
let (lh, rh) = (self.l.height, self.r.height);
std::cmp::max(lh, rh) - std::cmp::min(lh, rh) < 2 && self.l.balanced() && self.r.balanced()
let (hl, hr) = (self.l.height, self.r.height);
std::cmp::max(hl, hr) - std::cmp::min(hl, hr) < 2 && self.l.balanced() && self.r.balanced()
}
}

View File

@ -14,7 +14,7 @@ pub trait Effect {
fn e_pure() -> Self;
/// Used in [`ApplicativeLA2::la2`] and other [`Applicative`] methods.
fn e_seq(lhs: Self, rhs: Self) -> Self;
fn e_seq(el: Self, er: Self) -> Self;
/// Used in [`Monad::bind`] and other [`Monad`] methods.
fn e_after(self, effect: Self) -> Self;

View File

@ -21,14 +21,14 @@ impl<'a> EvalTree<'a> {
fn next(self) -> Oet<'a> {
match self {
EvalTree::Atom(f) => f(),
EvalTree::Composite(left, right) => match *left {
EvalTree::Composite(etl, etr) => match *etl {
EvalTree::Atom(f) => match f() {
Some(newleft) => Some(EvalTree::Composite(Box::new(newleft), right)),
None => Some(*right),
Some(newleft) => Some(EvalTree::Composite(Box::new(newleft), etr)),
None => Some(*etr),
},
EvalTree::Composite(leftleft, leftright) => Some(EvalTree::Composite(
leftleft,
Box::new(EvalTree::Composite(leftright, right)),
EvalTree::Composite(etll, etlr) => Some(EvalTree::Composite(
etll,
Box::new(EvalTree::Composite(etlr, etr)),
)),
},
}
@ -61,14 +61,14 @@ impl<'a, A: 'a> Stackless<'a, A> {
/// the preferred way to chain [`Stackless<A>`] and `FnOnce(A) -> Stackless<B>` into [`Stackless<B>`].
pub fn bind<B: 'a>(self, f: impl 'a + FnOnce(A) -> Stackless<'a, B>) -> Stackless<'a, B> {
Stackless(Box::new(|takesb| {
let lcell = Rc::new(Cell::new(None));
let rcell = lcell.clone();
let cell_l = Rc::new(Cell::new(None));
let cell_r = cell_l.clone();
Some(EvalTree::Composite(
Box::new(EvalTree::Atom(Box::new(move || {
self.call(move |a| set_cell(lcell, a))
self.call(move |a| set_cell(cell_l, a))
}))),
Box::new(EvalTree::Atom(Box::new(move || {
let stackless = f(get_cell(rcell));
let stackless = f(get_cell(cell_r));
Some(EvalTree::Atom(Box::new(|| stackless.0(takesb))))
}))),
))
@ -78,14 +78,14 @@ impl<'a, A: 'a> Stackless<'a, A> {
/// Method-like equivalent of [`Functor::fmap`].
pub fn map<B: 'a>(self, f: impl 'a + FnOnce(A) -> B) -> Stackless<'a, B> {
Stackless(Box::new(|takesb| {
let lcell = Rc::new(Cell::new(None));
let rcell = lcell.clone();
let cell_l = Rc::new(Cell::new(None));
let cell_r = cell_l.clone();
Some(EvalTree::Composite(
Box::new(EvalTree::Atom(Box::new(move || {
self.call(move |a| set_cell(lcell, a))
self.call(move |a| set_cell(cell_l, a))
}))),
Box::new(EvalTree::Atom(Box::new(move || {
let b = f(get_cell(rcell));
let b = f(get_cell(cell_r));
Some(EvalTree::Atom(Box::new(|| {
takesb(b);
None
@ -209,14 +209,14 @@ impl<'a> Monad<'a> for StacklessInstance {
fn join<A: 'a>(ffa: Self::F<Self::F<A>>) -> Self::F<A> {
Stackless(Box::new(|takesa| {
let lcell = Rc::new(Cell::new(None));
let rcell = lcell.clone();
let cell_l = Rc::new(Cell::new(None));
let cell_r = cell_l.clone();
Some(EvalTree::Composite(
Box::new(EvalTree::Atom(Box::new(move || {
ffa.call(move |a| set_cell(lcell, a))
ffa.call(move |a| set_cell(cell_l, a))
}))),
Box::new(EvalTree::Atom(Box::new(move || {
let stackless = get_cell(rcell);
let stackless = get_cell(cell_r);
Some(EvalTree::Atom(Box::new(|| stackless.0(takesa))))
}))),
))

View File

@ -64,7 +64,7 @@ impl Add for R {
success: self.success + rhs.success,
total: self.total + rhs.total,
result: match (self.result, rhs.result) {
(Err(le), Err(re)) => Err(le + "\n" + re.as_str()),
(Err(el), Err(er)) => Err(el + "\n" + er.as_str()),
(e, Ok(_)) => e,
(Ok(_), e) => e,
},
@ -77,12 +77,12 @@ impl AddAssign<R> for R {
self.success += rhs.success;
self.total += rhs.total;
match (&mut self.result, rhs.result) {
(Err(ref mut le), Err(re)) => {
*le += "\n";
*le += re.as_str()
(Err(ref mut el), Err(er)) => {
*el += "\n";
*el += er.as_str()
}
(_, Ok(_)) => {}
(lr, Err(re)) => *lr = Err(re),
(rl, Err(er)) => *rl = Err(er),
}
}
}

View File

@ -19,17 +19,17 @@ impl<'a> From<&'a [u8]> for SliceDeserializer<'a> {
impl<'a> Deserializer for SliceDeserializer<'a> {
fn read_n(&mut self, n: usize) -> &[u8] {
let (left, right) = self.slice.split_at(min(n, self.slice.len()));
self.slice = right;
self.pos += left.len();
left
let (slice_l, slice_r) = self.slice.split_at(min(n, self.slice.len()));
self.slice = slice_r;
self.pos += slice_l.len();
slice_l
}
fn read_all(&mut self) -> &[u8] {
let left = self.slice;
let slice_l = self.slice;
self.slice = &[];
self.pos += left.len();
left
self.pos += slice_l.len();
slice_l
}
fn tell(&self) -> usize {

View File

@ -51,7 +51,7 @@ impl<E: Display> Display for AvlError<E> {
Self::LeafHeight(height) => {
f.write_fmt(format_args!("invalid AVL leaf height: {height}!=0."))
}
Self::Balance(lh, rh) => f.write_fmt(format_args!("unbalanced AVL node: {lh} {rh}.")),
Self::Balance(hl, hr) => f.write_fmt(format_args!("unbalanced AVL node: {hl} {hr}.")),
Self::HeightOverflow => f.write_fmt(format_args!("AVL tree height overflow")),
Self::HeightMismatch { child, parent } => f.write_fmt(format_args!(
"AVL child-parent height mismatch: {child:?}, {parent}"
@ -120,9 +120,9 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> Mentionable<'a, Ctx> for Avl
}
}
fn balanced<E>(lh: u64, rh: u64) -> Result<(), AvlError<E>> {
if std::cmp::max(lh, rh) - std::cmp::min(lh, rh) > 1 {
return Err(AvlError::Balance(lh, rh));
fn balanced<E>(hl: u64, hr: u64) -> Result<(), AvlError<E>> {
if std::cmp::max(hl, hr) - std::cmp::min(hl, hr) > 1 {
return Err(AvlError::Balance(hl, hr));
}
Ok(())
}

View File

@ -113,28 +113,31 @@ impl<A> Bounds<A> {
) -> Result<Self, BoundsError<A>> {
if let Some(lr) = &l.r {
Self::ordered(lr, key, comparator)?
} else if let Some(ll) = &l.l {
Self::ordered(ll, key, comparator)?
}
if let Some(rl) = &r.l {
Self::ordered(key, rl, comparator)?
} else if let Some(rr) = &r.r {
Self::ordered(key, rr, comparator)?
}
Self::new(l.l, r.r, comparator)
}
pub fn equal_bound(
lhs: &Option<Rc<A>>,
rhs: &Option<Rc<A>>,
l: &Option<Rc<A>>,
r: &Option<Rc<A>>,
comparator: &impl Comparator<A>,
) -> bool {
match (lhs, rhs) {
match (l, r) {
(None, None) => true,
(Some(kl), Some(kr)) => matches!(comparator.pick_smaller(kl, kr), Comparison::E),
_ => false,
}
}
pub fn equal(lhs: &Self, rhs: &Self, comparator: &impl Comparator<A>) -> bool {
Self::equal_bound(&lhs.l, &rhs.l, comparator)
&& Self::equal_bound(&lhs.r, &rhs.r, comparator)
pub fn equal(bl: &Self, br: &Self, comparator: &impl Comparator<A>) -> bool {
Self::equal_bound(&bl.l, &br.l, comparator) && Self::equal_bound(&bl.r, &br.r, comparator)
}
}
@ -273,7 +276,7 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>> BoundReference<'a, Ctx, A> {
})
}
pub fn equal(lhs: &Self, rhs: &Self, comparator: &impl Comparator<A>) -> bool {
lhs.reference == rhs.reference && Bounds::equal(&lhs.bounds, &rhs.bounds, comparator)
pub fn equal(rl: &Self, rr: &Self, comparator: &impl Comparator<A>) -> bool {
rl.reference == rr.reference && Bounds::equal(&rl.bounds, &rr.bounds, comparator)
}
}

View File

@ -50,8 +50,8 @@ impl<'a, Ctx: Context<'a>, A: Mentionable<'a, Ctx>, C: 'a + Comparator<A>> Binar
Ctx::stuff(reference.resolve(self.comparator.clone()))
}
fn equal(&self, rhs: &Self::Reference, lhs: &Self::Reference) -> bool {
BoundReference::equal(lhs, rhs, self.comparator.as_ref())
fn equal(&self, rl: &Self::Reference, rr: &Self::Reference) -> bool {
BoundReference::equal(rl, rr, self.comparator.as_ref())
}
fn refer(&self, tree: &Self::Tree) -> Option<Self::Reference> {

View File

@ -31,8 +31,8 @@ impl instances::effect::Effect for TraceBox {
TraceBox::pure()
}
fn e_seq(lhs: Self, rhs: Self) -> Self {
TraceBox::parallel(lhs, rhs)
fn e_seq(el: Self, er: Self) -> Self {
TraceBox::parallel(el, er)
}
fn e_after(self, effect: Self) -> Self {

View File

@ -29,8 +29,8 @@ impl instances::effect::Effect for usize {
0
}
fn e_seq(lhs: Self, rhs: Self) -> Self {
max(lhs, rhs)
fn e_seq(el: Self, er: Self) -> Self {
max(el, er)
}
fn e_after(self, effect: Self) -> Self {