Skip to content
Extraits de code Groupes Projets
Vérifiée Valider 64948ce4 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

RUST: Add a way to get the content of a range in the database queue

parent efc5dc35
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
use std::collections::VecDeque;
use std::{
collections::VecDeque,
ops::{Index, Range},
slice::SliceIndex,
};
/// The number of priority levels in the queues. The higher the number, the
/// higher the priority.
......@@ -52,6 +56,12 @@ pub struct LktDatabaseQueueIter<'a> {
index: usize,
}
/// The iterator for a range of karas from the database queue.
pub struct LktDatabaseQueueRangeIter<'a> {
iterator: LktDatabaseQueueIter<'a>,
remaining: usize,
}
impl<'a> Iterator for LktDatabaseQueueIter<'a> {
type Item = u64;
......@@ -123,4 +133,18 @@ impl LktDatabaseQueue {
.find(|content| !content.is_empty())?;
level.pop_front()
}
pub fn range(&self, range: Range<usize>) -> LktDatabaseQueueRangeIter {
let mut iter = self.iter();
let remaining = range.end.checked_sub(range.start).unwrap_or(0);
if remaining >= 1 {
for _ in 0..range.start {
iter.next();
}
}
LktDatabaseQueueRangeIter {
iterator: iter,
remaining,
}
}
}
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter