From cf97ec0155f488b942013a89477a64991db5cac3 Mon Sep 17 00:00:00 2001 From: styppo Date: Mon, 22 Nov 2021 20:20:34 +0000 Subject: [PATCH] Display BitSets in a compact format --- collections/src/bitset.rs | 19 ++++++++++++++++--- handel/src/aggregation.rs | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/collections/src/bitset.rs b/collections/src/bitset.rs index 1fca8465fa..b4a339686f 100644 --- a/collections/src/bitset.rs +++ b/collections/src/bitset.rs @@ -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(()) diff --git a/handel/src/aggregation.rs b/handel/src/aggregation.rs index 07f7c1553c..6fce47a4c8 100644 --- a/handel/src/aggregation.rs +++ b/handel/src/aggregation.rs @@ -156,7 +156,7 @@ impl< trace!( "Checking for completed level {}: signers={:?}", level.id, - contribution.contributors().iter().collect::>() + contribution.contributors() ); // check if level already is completed