|
@@ -1,49 +1,3 @@
|
|
-/*
|
|
|
|
-Or MAYBE, just use Vec<bool> ?!
|
|
|
|
-While that would use more memory, it would certainly be faster!
|
|
|
|
-Is saving a few bytes (these days) worth it, really?
|
|
|
|
-
|
|
|
|
-The iterator would ... already be written for Vec<T>. :P
|
|
|
|
-(Buuut, not quite. I only want true values...)
|
|
|
|
-
|
|
|
|
-fn main() {
|
|
|
|
- let vector = vec![true, false, false, true];
|
|
|
|
-
|
|
|
|
- for z in vector.iter().enumerate().filter(|x| *x.1) {
|
|
|
|
- println!("{:?}", z);
|
|
|
|
- }
|
|
|
|
- for z in vector.iter().enumerate().filter(|x| *x.1) {
|
|
|
|
- println!("{:?}", z);
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-This returns (0, true), (3, true)
|
|
|
|
-
|
|
|
|
-fn main() {
|
|
|
|
- let vector = vec![true, false, false, true];
|
|
|
|
-
|
|
|
|
- let d : Vec<usize> = vector.iter().enumerate().filter(|x| *x.1).map(|x| x.0).collect();
|
|
|
|
- println!("{:?}", &d);
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-This returns (0,3) ! This is what I was looking for!
|
|
|
|
-I'd rather have an iterator (like I have below), but I might
|
|
|
|
-have to compromise here.
|
|
|
|
-
|
|
|
|
- let d = vector.iter().enumerate().filter(|x| *x.1).map(|x| x.0);
|
|
|
|
- for dv in d {
|
|
|
|
- println!(" {}", dv);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-There we go, map returns iterator. :D
|
|
|
|
-Enumerate creates (index, value),
|
|
|
|
-filter finds "true" items,
|
|
|
|
-map returns iterator (with index)!
|
|
|
|
-
|
|
|
|
-And we could handle any crazy size as well... :O
|
|
|
|
-
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
use std::ops::RangeBounds;
|
|
use std::ops::RangeBounds;
|
|
use std::fmt;
|
|
use std::fmt;
|
|
// use std::iter::{Map, Filter, Enumerate};
|
|
// use std::iter::{Map, Filter, Enumerate};
|
|
@@ -94,17 +48,19 @@ impl GenBits {
|
|
self.0.iter().enumerate().filter(|x| *x.1).map(|x| x.0)
|
|
self.0.iter().enumerate().filter(|x| *x.1).map(|x| x.0)
|
|
}
|
|
}
|
|
|
|
|
|
- /// The "default" iterator for GenBits returns this.
|
|
|
|
|
|
+ /// Iterate over all of the indexes that are set true.
|
|
pub fn iter(&self) -> impl Iterator<Item = usize> + '_ {
|
|
pub fn iter(&self) -> impl Iterator<Item = usize> + '_ {
|
|
self.0.iter().enumerate().filter(|x| *x.1).map(|x| x.0)
|
|
self.0.iter().enumerate().filter(|x| *x.1).map(|x| x.0)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // Nope. This isn't how the original iterator for GenBits worked.
|
|
/*
|
|
/*
|
|
pub fn iter(&self) -> std::slice::Iter<'_, bool> {
|
|
pub fn iter(&self) -> std::slice::Iter<'_, bool> {
|
|
self.0.iter()
|
|
self.0.iter()
|
|
}
|
|
}
|
|
*/
|
|
*/
|
|
|
|
|
|
|
|
+ #[must_use]
|
|
/// Display bits that are set.
|
|
/// Display bits that are set.
|
|
/// +1 is added to the display, so it matches the cell values (1..N)
|
|
/// +1 is added to the display, so it matches the cell values (1..N)
|
|
pub fn display(&self) -> String {
|
|
pub fn display(&self) -> String {
|