Update formatting

This commit is contained in:
Andras Schmelczer 2024-12-08 18:22:17 +00:00
parent dda356ea00
commit 49638e5aa7
No known key found for this signature in database
GPG key ID: FC8F2C3D3D1A718C
27 changed files with 239 additions and 232 deletions

View file

@ -21,9 +21,10 @@ where
#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;
use super::*;
#[test]
fn test_common_prefix_len() {
assert_eq!(

View file

@ -22,9 +22,10 @@ where
#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;
use super::*;
#[test]
fn test_common_suffix_len() {
assert_eq!(

View file

@ -1,9 +1,12 @@
use crate::Token;
/// Given two lists of tokens, returns the offset in the first (old) list from which the two lists have the same tokens until the end of the first list.
/// Thus, the suffix of the old list from the offset to the end is equal to a prefix of the new list.
/// Given two lists of tokens, returns the offset in the first (old) list from
/// which the two lists have the same tokens until the end of the first list.
/// Thus, the suffix of the old list from the offset to the end is equal to a
/// prefix of the new list.
///
/// If there is no overlap, the function returns the maxmium offset, the length of the old list.
/// If there is no overlap, the function returns the maxmium offset, the length
/// of the old list.
///
/// ## Example
/// ```
@ -27,9 +30,10 @@ where
#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;
use super::*;
#[test]
fn test_common_overlap() {
assert_eq!(find_common_overlap(&["".into()], &["".into()]), 0);

View file

@ -1,5 +1,4 @@
use std::cmp::Ordering;
use std::iter::Peekable;
use std::{cmp::Ordering, iter::Peekable};
pub struct MergeAscending<L, R, F, O>
where
@ -70,9 +69,10 @@ impl<T: ?Sized> MergeSorted for T where T: Iterator {}
#[cfg(test)]
mod tests {
use super::*;
use pretty_assertions::assert_eq;
use super::*;
#[test]
fn test_merge_sorted_by_key() {
let left = [9, 7, 5, 3, 1];

View file

@ -1,7 +1,8 @@
use std::ops::Range;
/// A helper for building a string in order based on an original string and a series of insertions and deletions applied to it.
/// It is safe to use with UTF-8 strings as all operations are based on character indices.
/// A helper for building a string in order based on an original string and a
/// series of insertions and deletions applied to it. It is safe to use with
/// UTF-8 strings as all operations are based on character indices.
#[derive(Debug, Clone)]
pub struct StringBuilder<'a> {
original: &'a str,
@ -18,13 +19,15 @@ impl StringBuilder<'_> {
}
}
/// Insert a string at the given index after copying the original string up to that index from the last insertion or deletion.
/// Insert a string at the given index after copying the original string up
/// to that index from the last insertion or deletion.
pub fn insert(&mut self, from: usize, text: &str) {
self.copy_until(from);
self.buffer.push_str(text);
}
/// Delete a string at the given index after copying the original string up to that index from the last insertion or deletion.
/// Delete a string at the given index after copying the original string up
/// to that index from the last insertion or deletion.
pub fn delete(&mut self, range: std::ops::Range<usize>) {
self.copy_until(range.start);
self.last_old_char_index += range.len();
@ -50,7 +53,8 @@ impl StringBuilder<'_> {
self.last_old_char_index += jump;
}
/// Finish building the string after copying the remaining original string since the last insertion or deletion.
/// Finish building the string after copying the remaining original string
/// since the last insertion or deletion.
pub fn build(mut self) -> String {
self.buffer.push_str(
&self