This commit is contained in:
Andras Schmelczer 2025-03-16 15:38:13 +00:00
parent 7eb740cd4c
commit 9f09b07de9
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
16 changed files with 191 additions and 114 deletions

View file

@ -99,7 +99,6 @@ impl IndexMut<isize> for V {
}
}
#[inline(always)]
fn split_at(range: Range<usize>, at: usize) -> (Range<usize>, Range<usize>) {
(range.start..at, at..range.end)
}

View file

@ -16,9 +16,9 @@ where
{
pub fn tokens(&self) -> &Vec<Token<T>> {
match self {
RawOperation::Insert(tokens) => tokens,
RawOperation::Delete(tokens) => tokens,
RawOperation::Equal(tokens) => tokens,
RawOperation::Insert(tokens)
| RawOperation::Delete(tokens)
| RawOperation::Equal(tokens) => tokens,
}
}

View file

@ -234,6 +234,7 @@ where
}
/// Apply the operations to the text and return the resulting text.
#[must_use]
pub fn apply(&self) -> String {
let mut builder: StringBuilder<'_> = StringBuilder::new(self.text);

View file

@ -1,8 +1,8 @@
use core::{
fmt::{Debug, Display},
use core::fmt::{Debug, Display};
use std::{
hash::{DefaultHasher, Hash, Hasher},
ops::Range,
};
use std::hash::{DefaultHasher, Hash, Hasher};
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
@ -57,7 +57,7 @@ where
index.hash(state);
deleted_character_count.hash(state);
}
};
}
}
}
@ -133,7 +133,7 @@ where
builder.delete(self.range());
}
};
}
builder
}
@ -141,8 +141,7 @@ where
/// Returns the index of the first character that the operation affects.
pub fn start_index(&self) -> usize {
match self {
Operation::Insert { index, .. } => *index,
Operation::Delete { index, .. } => *index,
Operation::Insert { index, .. } | Operation::Delete { index, .. } => *index,
}
}
@ -156,6 +155,7 @@ where
}
/// Returns the range of indices of characters that the operation affects.
#[allow(clippy::range_plus_one)]
pub fn range(&self) -> Range<usize> { self.start_index()..self.end_index() + 1 }
/// Returns the number of affected characters. It is always greater than 0
@ -382,7 +382,7 @@ mod tests {
use super::*;
#[test]
#[should_panic]
#[should_panic(expected = "Shifted index must be non-negative")]
fn test_shifting_error() {
insta::assert_debug_snapshot!(
Operation::create_insert(1, vec!["hi".into()])

View file

@ -46,8 +46,7 @@ where
};
match order {
Some(Ordering::Less) | None => self.left.next(),
Some(Ordering::Equal) => self.left.next(),
Some(Ordering::Less | Ordering::Equal) | None => self.left.next(),
Some(Ordering::Greater) => self.right.next(),
}
}