-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new: tcp.ports will now default to top common port
- Loading branch information
1 parent
92eee9f
commit 6eba10c
Showing
5 changed files
with
129 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
use crate::{creds, session::Error}; | ||
|
||
pub(crate) struct Multi { | ||
curr_it: usize, | ||
num_its: usize, | ||
elements: usize, | ||
iters: Vec<Box<dyn creds::Iterator<Item = String>>>, | ||
} | ||
|
||
impl Multi { | ||
pub fn new(iters: Vec<Box<dyn creds::Iterator<Item = String>>>) -> Result<Self, Error> { | ||
log::debug!("loading Multi with {} iterators ...", iters.len()); | ||
|
||
// count the number of items for each iterator | ||
let curr_it = 0; | ||
let num_its = iters.len(); | ||
let mut elements = 0; | ||
for it in iters.iter() { | ||
elements += it.search_space_size(); | ||
} | ||
|
||
Ok(Self { | ||
elements, | ||
curr_it, | ||
num_its, | ||
iters, | ||
}) | ||
} | ||
} | ||
|
||
impl creds::Iterator for Multi { | ||
fn search_space_size(&self) -> usize { | ||
self.elements | ||
} | ||
} | ||
|
||
impl creds::IteratorClone for Multi { | ||
fn create_boxed_copy(&self) -> Box<dyn creds::Iterator> { | ||
Box::new(Self::new(self.iters.clone()).unwrap()) | ||
} | ||
} | ||
|
||
impl std::iter::Iterator for Multi { | ||
type Item = String; | ||
|
||
fn next(&mut self) -> Option<Self::Item> { | ||
if self.curr_it < self.num_its { | ||
let curr = &mut self.iters[self.curr_it]; | ||
let next = curr.next(); | ||
return if next.is_none() { | ||
self.curr_it += 1; | ||
self.next() | ||
} else { | ||
next | ||
}; | ||
} | ||
None | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters