Start tracking diffs in ScriptingSession (#26463)

The diff is not exposed yet, but we'll take care of that next.

Release Notes:

- N/A
This commit is contained in:
Antonio Scandurra 2025-03-12 08:32:29 +01:00 committed by GitHub
parent 036c123488
commit 30afba50a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 207 additions and 64 deletions

View file

@ -70,6 +70,14 @@ impl<K: Clone + Ord, V: Clone> TreeMap<K, V> {
self.0.insert_or_replace(MapEntry { key, value }, &());
}
pub fn extend(&mut self, iter: impl IntoIterator<Item = (K, V)>) {
let mut edits = Vec::new();
for (key, value) in iter {
edits.push(Edit::Insert(MapEntry { key, value }));
}
self.0.edit(edits, &());
}
pub fn clear(&mut self) {
self.0 = SumTree::default();
}
@ -109,7 +117,7 @@ impl<K: Clone + Ord, V: Clone> TreeMap<K, V> {
cursor.item().map(|item| (&item.key, &item.value))
}
pub fn iter_from<'a>(&'a self, from: &'a K) -> impl Iterator<Item = (&'a K, &'a V)> + 'a {
pub fn iter_from<'a>(&'a self, from: &K) -> impl Iterator<Item = (&'a K, &'a V)> + 'a {
let mut cursor = self.0.cursor::<MapKeyRef<'_, K>>(&());
let from_key = MapKeyRef(Some(from));
cursor.seek(&from_key, Bias::Left, &());
@ -313,6 +321,10 @@ where
self.0.insert(key, ());
}
pub fn extend(&mut self, iter: impl IntoIterator<Item = K>) {
self.0.extend(iter.into_iter().map(|key| (key, ())));
}
pub fn contains(&self, key: &K) -> bool {
self.0.get(key).is_some()
}
@ -320,6 +332,10 @@ where
pub fn iter(&self) -> impl Iterator<Item = &K> + '_ {
self.0.iter().map(|(k, _)| k)
}
pub fn iter_from<'a>(&'a self, key: &K) -> impl Iterator<Item = &'a K> + 'a {
self.0.iter_from(key).map(move |(k, _)| k)
}
}
#[cfg(test)]
@ -422,6 +438,20 @@ mod tests {
assert_eq!(map.get(&"d"), Some(&4));
}
#[test]
fn test_extend() {
let mut map = TreeMap::default();
map.insert("a", 1);
map.insert("b", 2);
map.insert("c", 3);
map.extend([("a", 2), ("b", 2), ("d", 4)]);
assert_eq!(map.iter().count(), 4);
assert_eq!(map.get(&"a"), Some(&2));
assert_eq!(map.get(&"b"), Some(&2));
assert_eq!(map.get(&"c"), Some(&3));
assert_eq!(map.get(&"d"), Some(&4));
}
#[test]
fn test_remove_between_and_path_successor() {
use std::path::{Path, PathBuf};