persistent_range_query: more refs

This commit is contained in:
Egor Suvorov
2022-11-24 03:45:02 +02:00
parent 3a4b932d8a
commit 6188315b51
4 changed files with 21 additions and 21 deletions
+2 -2
View File
@@ -46,7 +46,7 @@ pub trait RangeModification<Key> {
}
pub trait VecReadableVersion<Modification: RangeModification<Key>, Key> {
fn get(&self, keys: Range<Key>) -> Modification::Result;
fn get(&self, keys: &Range<Key>) -> Modification::Result;
}
// TODO: use trait alias when stabilized
@@ -73,6 +73,6 @@ pub trait PersistentVecStorage<
type FrozenVersion: VecFrozenVersion<Modification, Key>;
fn modify(&mut self, keys: Range<Key>, modification: Modification);
fn modify(&mut self, keys: &Range<Key>, modification: &Modification);
fn freeze(&mut self) -> Self::FrozenVersion;
}
+4 -4
View File
@@ -19,7 +19,7 @@ pub trait IndexableKey: Clone {
fn get<Modification: RangeModification<Key>, Key: IndexableKey>(
all_keys: &Range<Key>,
values: &Vec<Modification::Result>,
keys: Range<Key>,
keys: &Range<Key>,
) -> Modification::Result {
let mut result = Modification::Result::new_for_empty_range();
let mut result_range = keys.start.clone()..keys.start.clone();
@@ -36,7 +36,7 @@ fn get<Modification: RangeModification<Key>, Key: IndexableKey>(
impl<Modification: RangeModification<Key>, Key: IndexableKey> VecReadableVersion<Modification, Key>
for NaiveFrozenVersion<Modification, Key>
{
fn get(&self, keys: Range<Key>) -> Modification::Result {
fn get(&self, keys: &Range<Key>) -> Modification::Result {
get::<Modification, Key>(&self.all_keys, &self.values, keys)
}
}
@@ -71,7 +71,7 @@ impl<
Key: IndexableKey,
> VecReadableVersion<Modification, Key> for NaiveVecStorage<Modification, Initializer, Key>
{
fn get(&self, keys: Range<Key>) -> Modification::Result {
fn get(&self, keys: &Range<Key>) -> Modification::Result {
get::<Modification, Key>(&self.all_keys, &self.last_version, keys)
}
}
@@ -97,7 +97,7 @@ impl<
type FrozenVersion = NaiveFrozenVersion<Modification, Key>;
fn modify(&mut self, keys: Range<Key>, modification: Modification) {
fn modify(&mut self, keys: &Range<Key>, modification: &Modification) {
for index in IndexableKey::index(&self.all_keys, &keys.start)
..IndexableKey::index(&self.all_keys, &keys.end)
{
@@ -194,12 +194,12 @@ impl<
> VecReadableVersion<Modification, Key>
for PersistentSegmentTreeVersion<Modification, Initializer, Key>
{
fn get(&self, keys: Range<Key>) -> Modification::Result {
fn get(&self, keys: &Range<Key>) -> Modification::Result {
get(
&mut self.root.clone(), // TODO: do not always force a branch
&self.all_keys,
self.initializer.as_ref(),
&keys,
keys,
)
}
}
@@ -217,7 +217,7 @@ impl<
> VecReadableVersion<Modification, Key>
for PersistentSegmentTree<Modification, Initializer, Key>
{
fn get(&self, keys: Range<Key>) -> Modification::Result {
fn get(&self, keys: &Range<Key>) -> Modification::Result {
self.0.get(keys)
}
}
@@ -239,13 +239,13 @@ impl<
type FrozenVersion = PersistentSegmentTreeVersion<Modification, Initializer, Key>;
fn modify(&mut self, keys: Range<Key>, modification: Modification) {
fn modify(&mut self, keys: &Range<Key>, modification: &Modification) {
modify(
&mut self.0.root, // TODO: do not always force a branch
&self.0.all_keys,
self.0.initializer.as_ref(),
&keys,
&modification,
keys,
modification,
)
}
@@ -34,20 +34,20 @@ fn test_storage<
S: PersistentVecStorage<AddAssignModification<i32>, SameElementsInitializer<i32>, K>,
>() {
let mut s = S::new(K(0)..K(12), SameElementsInitializer::new(0i32));
assert_eq!(*s.get(K(0)..K(12)).sum(), 0);
assert_eq!(*s.get(&(K(0)..K(12))).sum(), 0);
s.modify(K(2)..K(5), AddAssignModification::Add(3));
assert_eq!(*s.get(K(0)..K(12)).sum(), 3 + 3 + 3);
s.modify(&(K(2)..K(5)), &AddAssignModification::Add(3));
assert_eq!(*s.get(&(K(0)..K(12))).sum(), 3 + 3 + 3);
let s_old = s.freeze();
s.modify(K(3)..K(6), AddAssignModification::Assign(10));
assert_eq!(*s.get(K(0)..K(12)).sum(), 3 + 10 + 10 + 10);
s.modify(&(K(3)..K(6)), &AddAssignModification::Assign(10));
assert_eq!(*s.get(&(K(0)..K(12))).sum(), 3 + 10 + 10 + 10);
s.modify(K(4)..K(7), AddAssignModification::Add(2));
assert_eq!(*s.get(K(0)..K(12)).sum(), 3 + 10 + 12 + 12 + 2);
s.modify(&(K(4)..K(7)), &AddAssignModification::Add(2));
assert_eq!(*s.get(&(K(0)..K(12))).sum(), 3 + 10 + 12 + 12 + 2);
assert_eq!(*s.get(K(4)..K(6)).sum(), 12 + 12);
assert_eq!(*s_old.get(K(4)..K(6)).sum(), 3);
assert_eq!(*s.get(&(K(4)..K(6))).sum(), 12 + 12);
assert_eq!(*s_old.get(&(K(4)..K(6))).sum(), 3);
}
#[test]