Skip to content

Commit

Permalink
added Debug impl for LimitHeap
Browse files Browse the repository at this point in the history
  • Loading branch information
epi052 committed Feb 18, 2021
1 parent 9e0118f commit 13222bf
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/scanner/limit_heap.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::{Debug, Formatter, Result};

/// bespoke variation on an array-backed max-heap
///
/// 255 possible values generated from the initial requests/second
Expand All @@ -8,7 +10,6 @@
/// formula for each child:
/// - left: (|parent - current|) / 2 + current
/// - right: current - ((|parent - current|) / 2)
#[derive(Debug)]
pub(super) struct LimitHeap {
/// backing array, 255 nodes == height of 7 ( 2^(h+1) -1 nodes )
pub(super) inner: [i32; 255],
Expand All @@ -32,6 +33,18 @@ impl Default for LimitHeap {
}
}

/// Debug implementation of a LimitHeap
impl Debug for LimitHeap {
/// return debug representation that conforms to <32 elements in array
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
let msg = format!(
"LimitHeap {{ original: {}, current: {}, inner: [{}...] }}",
self.original, self.current, self.inner[0]
);
write!(f, "{}", msg)
}
}

/// implementation of a LimitHeap
impl LimitHeap {
/// move to right child, return node's index from which the move was requested
Expand Down

0 comments on commit 13222bf

Please sign in to comment.