Use a faster stack impl

pull/393/head
QuarticCat 2022-09-28 04:08:42 +07:00
parent 06b46e9355
commit d48ee2dfdb
No known key found for this signature in database
GPG Key ID: 441CE956DEADBEEF
5 changed files with 53 additions and 28 deletions

25
Cargo.lock generated

@ -20,15 +20,6 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "archery"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0a8da9bc4c4053ee067669762bcaeea6e241841295a2b6c948312dad6ef4cc02"
dependencies = [
"static_assertions",
]
[[package]] [[package]]
name = "atty" name = "atty"
version = "0.2.14" version = "0.2.14"
@ -204,7 +195,6 @@ dependencies = [
"radix-heap", "radix-heap",
"rayon", "rayon",
"regex", "regex",
"rpds",
"rustc-hash", "rustc-hash",
"strsim", "strsim",
"term_size", "term_size",
@ -535,15 +525,6 @@ version = "0.6.26"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64" checksum = "49b3de9ec5dc0a3417da371aab17d729997c15010e7fd24ff707773a33bddb64"
[[package]]
name = "rpds"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "054e417ded02a19ae192c8c89412eaec7d1c2cdd826aa412565761d86ca6315e"
dependencies = [
"archery",
]
[[package]] [[package]]
name = "rustc-hash" name = "rustc-hash"
version = "1.1.0" version = "1.1.0"
@ -579,12 +560,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "static_assertions"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]] [[package]]
name = "strsim" name = "strsim"
version = "0.10.0" version = "0.10.0"

@ -42,7 +42,6 @@ walkdir = "2.3.2"
terminal_size = "0.2.1" terminal_size = "0.2.1"
const_format = "0.2.22" const_format = "0.2.22"
owo-colors = "3.3.0" owo-colors = "3.3.0"
rpds = "0.10.0"
wu-diff = "0.1.2" wu-diff = "0.1.2"
rayon = "1.5.2" rayon = "1.5.2"
tree_magic_mini = "3.0.3" tree_magic_mini = "3.0.3"

@ -1,7 +1,6 @@
//! A graph representation for computing tree diffs. //! A graph representation for computing tree diffs.
use bumpalo::Bump; use bumpalo::Bump;
use rpds::Stack;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use std::{ use std::{
cell::RefCell, cell::RefCell,
@ -12,7 +11,10 @@ use std::{
use strsim::normalized_levenshtein; use strsim::normalized_levenshtein;
use crate::{ use crate::{
diff::changes::{insert_deep_unchanged, ChangeKind, ChangeMap}, diff::{
changes::{insert_deep_unchanged, ChangeKind, ChangeMap},
stack::Stack,
},
parse::syntax::{AtomKind, Syntax, SyntaxId}, parse::syntax::{AtomKind, Syntax, SyntaxId},
}; };
use Edge::*; use Edge::*;

@ -3,4 +3,5 @@ pub mod dijkstra;
mod graph; mod graph;
pub mod myers_diff; pub mod myers_diff;
pub mod sliders; pub mod sliders;
mod stack;
pub mod unchanged; pub mod unchanged;

@ -0,0 +1,48 @@
use std::rc::Rc;
#[derive(Debug, Clone, Default, PartialEq, Eq)]
struct Node<T> {
val: T,
next: Option<Rc<Node<T>>>,
}
#[derive(Debug, Clone, Default, PartialEq, Eq)]
pub struct Stack<T> {
head: Option<Rc<Node<T>>>,
len: usize,
}
impl<T> Stack<T> {
pub fn new() -> Self {
Self { head: None, len: 0 }
}
pub fn peek(&self) -> Option<&T> {
self.head.as_deref().map(|n| &n.val)
}
pub fn pop(&self) -> Option<Stack<T>> {
self.head.as_deref().map(|n| Self {
head: n.next.clone(),
len: self.len - 1,
})
}
pub fn push(&self, v: T) -> Stack<T> {
Self {
head: Some(Rc::new(Node {
val: v,
next: self.head.clone(),
})),
len: self.len + 1,
}
}
pub fn size(&self) -> usize {
self.len
}
pub fn is_empty(&self) -> bool {
self.len == 0
}
}