Skip to content

Commit

Permalink
Display BitSets in a compact format
Browse files Browse the repository at this point in the history
  • Loading branch information
styppo committed Nov 22, 2021
1 parent 7d630a8 commit cf97ec0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
19 changes: 16 additions & 3 deletions collections/src/bitset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,12 +322,25 @@ impl Deserialize for BitSet {
impl fmt::Display for BitSet {
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
write!(f, "[")?;
let mut last_value = None;
let mut it = self.iter().peekable();
while let Some(value) = it.next() {
write!(f, "{}", value)?;
if it.peek().is_some() {
write!(f, ", ")?;
let next_value = it.peek();
if let Some(next_value) = next_value {
let consecutive_last = last_value.map(|lv| lv + 1 == value).unwrap_or(false);
let consecutive_next = value + 1 == *next_value;
if !(consecutive_last && consecutive_next) {
write!(f, "{}", value.to_string())?;
if consecutive_next {
write!(f, "-")?;
} else {
write!(f, ", ")?;
}
}
} else {
write!(f, "{}", value.to_string())?;
}
last_value = Some(value);
}
write!(f, "]")?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion handel/src/aggregation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl<
trace!(
"Checking for completed level {}: signers={:?}",
level.id,
contribution.contributors().iter().collect::<Vec<usize>>()
contribution.contributors()
);

// check if level already is completed
Expand Down

0 comments on commit cf97ec0

Please sign in to comment.