Store tokens instead of text in insert

This commit is contained in:
Andras Schmelczer 2024-11-28 20:51:05 +00:00
parent 3391d2c0ec
commit 44f9a44f63
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
10 changed files with 144 additions and 74 deletions

View file

@ -18,7 +18,6 @@
//! without making reasonable progress.
//! For potential improvements here see [similar#15](https://github.com/mitsuhiko/similar/issues/15).
use std::hash::Hash;
use std::ops::{Index, IndexMut, Range};
use std::vec;
@ -36,7 +35,7 @@ use super::raw_operation::RawOperation;
/// execution time permitted before it bails and falls back to an approximation.
pub fn diff<T>(old: &[Token<T>], new: &[Token<T>]) -> Vec<RawOperation<T>>
where
T: PartialEq + Hash + Clone,
T: PartialEq + Clone,
{
let max_d = max_d(old.len(), new.len());
let mut vb = V::new(max_d);
@ -131,7 +130,7 @@ fn find_middle_snake<T>(
vb: &mut V,
) -> Option<(usize, usize)>
where
T: PartialEq + Hash + Clone,
T: PartialEq + Clone,
{
let n = old_range.len();
let m = new_range.len();
@ -238,7 +237,7 @@ fn conquer<T>(
vb: &mut V,
result: &mut Vec<RawOperation<T>>,
) where
T: PartialEq + Hash + Clone,
T: PartialEq + Clone,
{
// Check for common prefix
let common_prefix_len = common_prefix_len(old, old_range.clone(), new, new_range.clone());

View file

@ -1,10 +1,9 @@
use crate::tokenizer::token::Token;
use std::hash::Hash;
#[derive(Debug, Clone, PartialEq)]
pub enum RawOperation<T>
where
T: PartialEq + Hash + Clone,
T: PartialEq + Clone,
{
Insert(Vec<Token<T>>),
Delete(Vec<Token<T>>),
@ -13,7 +12,7 @@ where
impl<T> RawOperation<T>
where
T: PartialEq + Hash + Clone,
T: PartialEq + Clone,
{
pub fn tokens(&self) -> &Vec<Token<T>> {
match self {