blob: 3d04f1cb130e1a65434741b06f5c95272b672dc7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
//! ref: composer/src/Composer/DependencyResolver/RuleWatchChain.php
use crate::dependency_resolver::rule_watch_node::RuleWatchNode;
/// An extension of SplDoublyLinkedList with seek and removal of current element.
pub struct RuleWatchChain {
data: Vec<RuleWatchNode>,
current_offset: usize,
}
impl RuleWatchChain {
pub fn new() -> Self {
Self {
data: Vec::new(),
current_offset: 0,
}
}
fn rewind(&mut self) {
self.current_offset = 0;
}
fn next(&mut self) {
self.current_offset += 1;
}
fn key(&self) -> usize {
self.current_offset
}
fn offset_unset(&mut self, offset: usize) {
self.data.remove(offset);
}
/// Moves the internal iterator to the specified offset.
pub fn seek(&mut self, offset: usize) {
self.rewind();
for _ in 0..offset {
self.next();
}
}
/// Removes the current element from the list.
pub fn remove(&mut self) {
let offset = self.key();
self.offset_unset(offset);
self.seek(offset);
}
}
|