Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: Allow diffing between data types besides strings #37

Open
2 tasks
neoncitylights opened this issue Jan 5, 2023 · 0 comments
Open
2 tasks

feature: Allow diffing between data types besides strings #37

neoncitylights opened this issue Jan 5, 2023 · 0 comments
Labels
lvl-2-medium Medium-ranking issue p2-normal Priority 2: Someone plans to work on this task in the foreseeable future. t-feature-request Type: Idea/request of an enhancement towards a library/framework

Comments

@neoncitylights
Copy link
Contributor

This task is blocked by #36.

  • Remove String prefix from StringDiffAlgorithm, StringDiffOp, and StringDiffOpKind
  • Make types generic

At the minimum, types would need to implement PartialEq and Eq so we can compare them for equality.

With reference to #36, the public API would look (similar-ish) to the following below. However, we need to consider for the case where the type is a string (str). In this case, the caller could call as_bytes() on both of their strings to pass in a &[u8].

pub enum DiffOpKind<T: PartialEq> {
    Substitute(T, T),
    Insert(T),
    Delete,
    Transpose,
}

pub struct DiffOp<T: PartialEq> {
   kind: DiffOpKind<T>,
   index: usize,
}

impl DiffOp<T> {
	pub fn new(kind: DiffOpKind<T>, index: usize) -> Self {
		Self { kind, index }
	}

	pub fn new_delete(index: usize) -> Self {
		Self::new(DiffOpKind<T>::Delete, index)
	}

	pub fn new_insert(val: T, index: usize) -> Self {
		Self::new(DiffOpKind<T>::Insert(val), index)
	}

	pub fn new_substitute(val1: T, val2: T, index: usize) -> Self {
		Self::new(DiffOpKind<T>::Substitute(val1, val2), index)
	}
}

pub fn apply_diff<'a, T>(a: &'a [T], b: &'a [T]) -> T where T: PartialEq { /* ... */ }
pub fn hamming<'a, T>(a: &'a [T], b: &'a [T]) -> T where T: PartialEq { /* ... */ }
pub fn levenshtein<'a, T>(a: &'a [T], b: &'a [T]) -> T where T: PartialEq { /* ... */ }
@neoncitylights neoncitylights added lvl-2-medium Medium-ranking issue p2-normal Priority 2: Someone plans to work on this task in the foreseeable future. t-feature-request Type: Idea/request of an enhancement towards a library/framework labels Jan 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lvl-2-medium Medium-ranking issue p2-normal Priority 2: Someone plans to work on this task in the foreseeable future. t-feature-request Type: Idea/request of an enhancement towards a library/framework
Projects
None yet
Development

No branches or pull requests

1 participant