tglman / persy
Showing 1 of 1 files from the diff.

@@ -68,6 +68,21 @@
Loading
68 68
    fn apply(&mut self, adds: &[KeyChanges<K, V>]) -> PIRes<()>;
69 69
}
70 70
71 +
struct Updated<K> {
72 +
    path: Vec<PosRef<K>>,
73 +
}
74 +
impl<K> Updated<K> {
75 +
    fn new() -> Self {
76 +
        Self { path: Vec::new() }
77 +
    }
78 +
    fn push(&mut self, p: PosRef<K>) {
79 +
        self.path.push(p)
80 +
    }
81 +
    fn clear(&mut self) {
82 +
        self.path.clear();
83 +
    }
84 +
}
85 +
71 86
#[derive(PartialEq, Clone, Debug)]
72 87
pub struct PosRef<K> {
73 88
    pub k: K,
@@ -90,7 +105,7 @@
Loading
90 105
}
91 106
92 107
struct ParentNodeChanged<K> {
93 -
    path: Vec<PosRef<K>>,
108 +
    path: Updated<K>,
94 109
    children: Vec<PosRef<K>>,
95 110
}
96 111
@@ -126,13 +141,13 @@
Loading
126 141
    Ok(ids)
127 142
}
128 143
129 -
fn group_by_parent<K>(updates: Vec<Vec<PosRef<K>>>) -> Vec<ParentNodeChanged<K>> {
144 +
fn group_by_parent<K>(updates: Vec<Updated<K>>) -> Vec<ParentNodeChanged<K>> {
130 145
    let mut parent_updates = Vec::new();
131 146
    let mut parent_node: Option<NodeRef> = None;
132 147
    let mut new_update: Option<ParentNodeChanged<K>> = None;
133 148
    for mut update in updates {
134 -
        if let Some(last) = update.pop() {
135 -
            if parent_node == update.last().map(|x| x.node_ref.clone()) {
149 +
        if let Some(last) = update.path.pop() {
150 +
            if parent_node == update.path.last().map(|x| x.node_ref.clone()) {
136 151
                if let Some(p) = &mut new_update {
137 152
                    p.children.push(last);
138 153
                }
@@ -140,7 +155,7 @@
Loading
140 155
                if let Some(p) = new_update {
141 156
                    parent_updates.push(p);
142 157
                }
143 -
                parent_node = update.last().map(|x| x.node_ref.clone());
158 +
                parent_node = update.path.last().map(|x| x.node_ref.clone());
144 159
                let children = vec![last];
145 160
                new_update = Some(ParentNodeChanged { path: update, children });
146 161
            }
@@ -153,18 +168,18 @@
Loading
153 168
}
154 169
fn lock_parents<K: IndexOrd + Clone, V, I: IndexModify<K, V>>(
155 170
    index: &mut I,
156 -
    mut updates: Vec<Vec<PosRef<K>>>,
157 -
) -> PIRes<Vec<Vec<PosRef<K>>>> {
171 +
    mut updates: Vec<Updated<K>>,
172 +
) -> PIRes<Vec<Updated<K>>> {
158 173
    for update in &mut updates {
159 174
        loop {
160 175
            debug_assert!(
161 -
                update.len() >= 2,
176 +
                update.path.len() >= 2,
162 177
                "never lock a path that shorter than 2 because that would be the root",
163 178
            );
164 179
            let locked = {
165 180
                let update = &update;
166 -
                let len = update.len();
167 -
                let rec_ref = &update[len - 2];
181 +
                let len = update.path.len();
182 +
                let rec_ref = &update.path[len - 2];
168 183
                if let Some((node, version)) = index.load_modify(&rec_ref.node_ref)? {
169 184
                    lock_logic(index, rec_ref, node, version)?.is_some()
170 185
                } else {
@@ -174,7 +189,7 @@
Loading
174 189
            if locked {
175 190
                break;
176 191
            } else {
177 -
                let last = update.last().unwrap().clone();
192 +
                let last = update.path.last().unwrap().clone();
178 193
                if let Some(ref node) = index.get_root_refresh()? {
179 194
                    let mut path = Vec::new();
180 195
                    let mut cur_node = PosRef::new(&last.k, 0, node.clone(), None);
@@ -200,7 +215,7 @@
Loading
200 215
                        }
201 216
                    }
202 217
                    path.push(last);
203 -
                    *update = path;
218 +
                    update.path = path;
204 219
                }
205 220
            }
206 221
        }
@@ -292,12 +307,12 @@
Loading
292 307
293 308
fn find_and_change_leaf<K: IndexType, V: IndexType, I: IndexModify<K, V>>(
294 309
    add: &KeyChanges<K, V>,
295 -
    updates: &mut Vec<Vec<PosRef<K>>>,
310 +
    updates: &mut Vec<Updated<K>>,
296 311
    index: &mut I,
297 312
    mut prev_leaf_id: Option<NodeRef>,
298 313
) -> PIRes<Option<NodeRef>> {
299 314
    let mut next: Option<PosRef<K>> = None;
300 -
    let mut path = Vec::new();
315 +
    let mut path = Updated::new();
301 316
    loop {
302 317
        next = if let Some(cur_node) = &mut next {
303 318
            let mut new_next = None;
@@ -356,12 +371,12 @@
Loading
356 371
        for add in adds {
357 372
            prev_leaf_id = find_and_change_leaf(add, &mut updates, self, prev_leaf_id)?;
358 373
        }
359 -
        while updates.len() > 1 || (updates.len() == 1 && updates[0].len() > 1) {
374 +
        while updates.len() > 1 || (updates.len() == 1 && updates[0].path.len() > 1) {
360 375
            updates = lock_parents(self, updates)?;
361 376
            let parent_updates = group_by_parent(updates);
362 377
            updates = Vec::new();
363 378
            for update in parent_updates {
364 -
                let parent_id = update.path.last().unwrap().node_ref.clone();
379 +
                let parent_id = update.path.path.last().unwrap().node_ref.clone();
365 380
                // It's locked, should not have miss read unwrap.
366 381
                let (read_node, n_version) = self.load_modify(&parent_id)?.unwrap();
367 382
                if let Node::Node(mut n) = self.owned(&parent_id, read_node) {
@@ -410,7 +425,7 @@
Loading
410 425
                    }
411 426
                    if save {
412 427
                        self.update(&parent_id, Node::Node(n), n_version)?;
413 -
                        if !update.path.is_empty() {
428 +
                        if !update.path.path.is_empty() {
414 429
                            updates.push(update.path);
415 430
                        } else {
416 431
                            break;
@@ -419,7 +434,7 @@
Loading
419 434
                }
420 435
            }
421 436
        }
422 -
        if updates.len() == 1 && updates[0].len() == 1 {
437 +
        if updates.len() == 1 && updates[0].path.len() == 1 {
423 438
            self.lock_config()?;
424 439
            while let Some(r) = self.get_root_refresh()? {
425 440
                if let Some((n, n_version)) = self.load_modify(&r)? {
Files Coverage
src 91.73%
tests 98.71%
Project Totals (37 files) 93.09%
Notifications are pending CI completion. Waiting for GitLab's status webhook to queue notifications. Push notifications now.
1
coverage:
2
  status:
3
    project:
4
      default:
5
        target: 80%
6
        threshold: 1.0%
7
    patch: off
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading