Skip to content

Commit

Permalink
EventClock: Make Debug representation more compact
Browse files Browse the repository at this point in the history
  • Loading branch information
progval authored and spb committed Nov 10, 2024
1 parent 554442f commit 4a1589c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions sable_network/src/network/event/clock.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use serde::{Deserialize, Serialize};
use std::cmp::Ordering;
use std::collections::HashMap;
use std::hash::Hash;

use itertools::Itertools;
use serde::{Deserialize, Serialize};

use crate::prelude::*;

/// A vector clock defining, for each server, the most recent event from that
Expand All @@ -14,7 +16,7 @@ use crate::prelude::*;
/// these, a server receiving a remote event can determine whether the incoming
/// event can be applied immediately, or whether missing dependencies need to
/// be requested.
#[derive(Clone, Eq, PartialEq, Debug, Serialize, Deserialize)]
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct EventClock(pub HashMap<ServerId, EventId>);

impl EventClock {
Expand Down Expand Up @@ -112,3 +114,15 @@ impl PartialOrd for EventClock {
}
}
}

impl std::fmt::Debug for EventClock {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut entries: Vec<_> = self.0.iter().collect();
entries.sort_unstable();
let entries = entries
.into_iter()
.map(|(k, v)| format!("{} => {}", **k, v.as_u64()))
.join(", ");
write!(f, "EventClock({})", entries)
}
}

0 comments on commit 4a1589c

Please sign in to comment.