Skip to content

Commit

Permalink
chore: Use upstream pad_{left, right}
Browse files Browse the repository at this point in the history
  • Loading branch information
uncomputable committed Sep 3, 2024
1 parent e96efea commit cf4a5a4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
9 changes: 0 additions & 9 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::sync::Arc;
use simplicity::dag::{DagLike, MaxSharing, NoSharing};
use simplicity::jet::Elements;
use simplicity::node::Inner;
use simplicity::types::Final;
use simplicity::{node, RedeemNode};

use crate::simplicity;
Expand Down Expand Up @@ -61,11 +60,3 @@ impl<'a, M: node::Marker> fmt::Debug for DisplayInner<'a, M> {
fmt::Display::fmt(self, f)
}
}

pub fn pad_left(a: &Final, b: &Final) -> usize {
std::cmp::max(a.bit_width(), b.bit_width()) - a.bit_width()
}

pub fn pad_right(a: &Final, b: &Final) -> usize {
std::cmp::max(a.bit_width(), b.bit_width()) - b.bit_width()
}
9 changes: 4 additions & 5 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use simplicity::types::Final;
use simplicity::Value;

use crate::simplicity;
use crate::util;

/// Immutable sequence of bits whose length is a power of two.
///
Expand Down Expand Up @@ -313,11 +312,11 @@ impl ExtValue {
} else if let Some((l_ty, r_ty)) = ty.as_sum() {
if let Some(l_value) = value.as_left() {
bits.push(false);
bits.extend(std::iter::repeat(false).take(util::pad_left(l_ty, r_ty)));
bits.extend(std::iter::repeat(false).take(l_ty.pad_left(r_ty)));
stack.push((l_value, l_ty));
} else if let Some(r_value) = value.as_right() {
bits.push(true);
bits.extend(std::iter::repeat(false).take(util::pad_right(l_ty, r_ty)));
bits.extend(std::iter::repeat(false).take(l_ty.pad_right(r_ty)));
stack.push((r_value, r_ty));
} else {
panic!("Value {value} is not of expected type {ty}");
Expand Down Expand Up @@ -427,13 +426,13 @@ impl ExtValue {
result_stack.push(Item::Value(ExtValue::Unit));
} else if let Some((l_ty, r_ty)) = ty.as_sum() {
if !it.next().ok_or("Not enough bits")? {
for _ in 0..util::pad_left(l_ty, r_ty) {
for _ in 0..l_ty.pad_left(r_ty) {
let _padding = it.next().ok_or("Not enough bits")?;
}
task_stack.push(Task::MakeLeft);
task_stack.push(Task::ReadType(l_ty));
} else {
for _ in 0..util::pad_right(l_ty, r_ty) {
for _ in 0..l_ty.pad_right(r_ty) {
let _padding = it.next().ok_or("Not enough bits")?;
}
task_stack.push(Task::MakeRight);
Expand Down

0 comments on commit cf4a5a4

Please sign in to comment.