Skip to content

Commit

Permalink
Add reversed and signed dict iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexagon committed Aug 14, 2023
1 parent ec5a56d commit b1dcf79
Show file tree
Hide file tree
Showing 4 changed files with 349 additions and 90 deletions.
20 changes: 20 additions & 0 deletions src/cell/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,26 @@ impl PartialEq for CellBuilder {
}
}

impl std::fmt::Debug for CellBuilder {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
#[repr(transparent)]
struct Data<'a, T>(&'a T);

impl<T: std::fmt::Display> std::fmt::Debug for Data<'_, T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.0, f)
}
}

f.debug_struct("CellBuilder")
.field("data", &Data(&self.display_data()))
.field("bit_len", &self.bit_len)
.field("is_exotic", &self.is_exotic)
.field("references", &self.references.as_ref())
.finish()
}
}

macro_rules! impl_store_uint {
($self:ident, $value:ident, bytes: $bytes:literal, bits: $bits:literal) => {
if $self.bit_len + $bits <= MAX_BIT_LEN {
Expand Down
14 changes: 14 additions & 0 deletions src/dict/aug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,20 @@ where
inner: Iter::new(root),
}
}

/// Changes the direction of the iterator to descending.
#[inline]
pub fn reversed(mut self) -> Self {
self.inner = self.inner.reversed();
self
}

/// Changes the behavior of the iterator to reverse the high bit.
#[inline]
pub fn signed(mut self) -> Self {
self.inner = self.inner.signed();
self
}
}

impl<'a, K, A, V> Iterator for AugIter<'a, K, A, V>
Expand Down
Loading

0 comments on commit b1dcf79

Please sign in to comment.