Skip to content

Commit

Permalink
chore: run cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mehulmathur16 committed Oct 3, 2024
1 parent d9e151c commit 42ccf90
Show file tree
Hide file tree
Showing 19 changed files with 141 additions and 72 deletions.
3 changes: 2 additions & 1 deletion crates/proof-of-sql/src/base/commitment/column_bounds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ impl ColumnBounds {
/// Construct a [`ColumnBounds`] from a column by reference.
///
/// If the column variant has order, only the minimum and maximum value will be copied.
#[must_use] pub fn from_column(column: &CommittableColumn) -> ColumnBounds {
#[must_use]
pub fn from_column(column: &CommittableColumn) -> ColumnBounds {
match column {
CommittableColumn::SmallInt(ints) => ColumnBounds::SmallInt(Bounds::from_iter(*ints)),
CommittableColumn::Int(ints) => ColumnBounds::Int(Bounds::from_iter(*ints)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ impl ColumnCommitmentMetadata {
}

/// Construct a [`ColumnCommitmentMetadata`] with widest possible bounds for the column type.
#[must_use] pub fn from_column_type_with_max_bounds(column_type: ColumnType) -> Self {
#[must_use]
pub fn from_column_type_with_max_bounds(column_type: ColumnType) -> Self {
let bounds = match column_type {
ColumnType::SmallInt => ColumnBounds::SmallInt(super::Bounds::Bounded(
BoundsInner::try_new(i16::MIN, i16::MAX)
Expand Down Expand Up @@ -100,17 +101,20 @@ impl ColumnCommitmentMetadata {
}

/// Immutable reference to this column's type.
#[must_use] pub fn column_type(&self) -> &ColumnType {
#[must_use]
pub fn column_type(&self) -> &ColumnType {
&self.column_type
}

/// Immutable reference to this column's bounds.
#[must_use] pub fn bounds(&self) -> &ColumnBounds {
#[must_use]
pub fn bounds(&self) -> &ColumnBounds {
&self.bounds
}

/// Contruct a [`ColumnCommitmentMetadata`] by analyzing a column.
#[must_use] pub fn from_column(column: &CommittableColumn) -> ColumnCommitmentMetadata {
#[must_use]
pub fn from_column(column: &CommittableColumn) -> ColumnCommitmentMetadata {
ColumnCommitmentMetadata {
column_type: column.column_type(),
bounds: ColumnBounds::from_column(column),
Expand Down
18 changes: 12 additions & 6 deletions crates/proof-of-sql/src/base/commitment/column_commitments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,34 +75,40 @@ impl<C: Commitment> ColumnCommitments<C> {
}

/// Returns a reference to the stored commitments.
#[must_use] pub fn commitments(&self) -> &Vec<C> {
#[must_use]
pub fn commitments(&self) -> &Vec<C> {
&self.commitments
}

/// Returns a reference to the stored column metadata.
#[must_use] pub fn column_metadata(&self) -> &ColumnCommitmentMetadataMap {
#[must_use]
pub fn column_metadata(&self) -> &ColumnCommitmentMetadataMap {
&self.column_metadata
}

/// Returns the number of columns.
#[must_use] pub fn len(&self) -> usize {
#[must_use]
pub fn len(&self) -> usize {
self.column_metadata.len()
}

/// Returns true if there are no columns.
#[must_use] pub fn is_empty(&self) -> bool {
#[must_use]
pub fn is_empty(&self) -> bool {
self.column_metadata.is_empty()
}

/// Returns the commitment with the given identifier.
#[must_use] pub fn get_commitment(&self, identifier: &Identifier) -> Option<C> {
#[must_use]
pub fn get_commitment(&self, identifier: &Identifier) -> Option<C> {
self.column_metadata
.get_index_of(identifier)
.map(|index| self.commitments[index].clone())
}

/// Returns the metadata for the commitment with the given identifier.
#[must_use] pub fn get_metadata(&self, identifier: &Identifier) -> Option<&ColumnCommitmentMetadata> {
#[must_use]
pub fn get_metadata(&self, identifier: &Identifier) -> Option<&ColumnCommitmentMetadata> {
self.column_metadata.get(identifier)
}

Expand Down
9 changes: 6 additions & 3 deletions crates/proof-of-sql/src/base/commitment/committable_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ pub enum CommittableColumn<'a> {

impl<'a> CommittableColumn<'a> {
/// Returns the length of the column.
#[must_use] pub fn len(&self) -> usize {
#[must_use]
pub fn len(&self) -> usize {
match self {
CommittableColumn::SmallInt(col) => col.len(),
CommittableColumn::Int(col) => col.len(),
Expand All @@ -64,12 +65,14 @@ impl<'a> CommittableColumn<'a> {
}

/// Returns true if the column is empty.
#[must_use] pub fn is_empty(&self) -> bool {
#[must_use]
pub fn is_empty(&self) -> bool {
self.len() == 0
}

/// Returns the type of the column.
#[must_use] pub fn column_type(&self) -> ColumnType {
#[must_use]
pub fn column_type(&self) -> ColumnType {
self.into()
}
}
Expand Down
12 changes: 8 additions & 4 deletions crates/proof-of-sql/src/base/commitment/table_commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,26 @@ impl<C: Commitment> TableCommitment<C> {
}

/// Returns a reference to this type's internal [`ColumnCommitments`].
#[must_use] pub fn column_commitments(&self) -> &ColumnCommitments<C> {
#[must_use]
pub fn column_commitments(&self) -> &ColumnCommitments<C> {
&self.column_commitments
}

/// Returns a reference to the range of rows this type commits to.
#[must_use] pub fn range(&self) -> &Range<usize> {
#[must_use]
pub fn range(&self) -> &Range<usize> {
&self.range
}

/// Returns the number of columns in the committed table.
#[must_use] pub fn num_columns(&self) -> usize {
#[must_use]
pub fn num_columns(&self) -> usize {
self.column_commitments.len()
}

/// Returns the number of rows that have been committed to.
#[must_use] pub fn num_rows(&self) -> usize {
#[must_use]
pub fn num_rows(&self) -> usize {
self.range.len()
}

Expand Down
54 changes: 36 additions & 18 deletions crates/proof-of-sql/src/base/database/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ pub enum Column<'a, S: Scalar> {

impl<'a, S: Scalar> Column<'a, S> {
/// Provides the column type associated with the column
#[must_use] pub fn column_type(&self) -> ColumnType {
#[must_use]
pub fn column_type(&self) -> ColumnType {
match self {
Self::Boolean(_) => ColumnType::Boolean,
Self::SmallInt(_) => ColumnType::SmallInt,
Expand All @@ -72,7 +73,8 @@ impl<'a, S: Scalar> Column<'a, S> {
}
}
/// Returns the length of the column.
#[must_use] pub fn len(&self) -> usize {
#[must_use]
pub fn len(&self) -> usize {
match self {
Self::Boolean(col) => col.len(),
Self::SmallInt(col) => col.len(),
Expand All @@ -89,7 +91,8 @@ impl<'a, S: Scalar> Column<'a, S> {
}
}
/// Returns `true` if the column has no elements.
#[must_use] pub fn is_empty(&self) -> bool {
#[must_use]
pub fn is_empty(&self) -> bool {
self.len() == 0
}

Expand Down Expand Up @@ -238,7 +241,8 @@ pub enum ColumnType {

impl ColumnType {
/// Returns true if this column is numeric and false otherwise
#[must_use] pub fn is_numeric(&self) -> bool {
#[must_use]
pub fn is_numeric(&self) -> bool {
matches!(
self,
ColumnType::SmallInt
Expand All @@ -251,7 +255,8 @@ impl ColumnType {
}

/// Returns true if this column is an integer and false otherwise
#[must_use] pub fn is_integer(&self) -> bool {
#[must_use]
pub fn is_integer(&self) -> bool {
matches!(
self,
ColumnType::SmallInt | ColumnType::Int | ColumnType::BigInt | ColumnType::Int128
Expand Down Expand Up @@ -285,7 +290,8 @@ impl ColumnType {
/// Returns the larger integer type of two ColumnTypes if they are both integers.
///
/// If either of the columns is not an integer, return None.
#[must_use] pub fn max_integer_type(&self, other: &Self) -> Option<Self> {
#[must_use]
pub fn max_integer_type(&self, other: &Self) -> Option<Self> {
// If either of the columns is not an integer, return None
if !self.is_integer() || !other.is_integer() {
return None;
Expand All @@ -298,7 +304,8 @@ impl ColumnType {
}

/// Returns the precision of a ColumnType if it is converted to a decimal wrapped in Some(). If it can not be converted to a decimal, return None.
#[must_use] pub fn precision_value(&self) -> Option<u8> {
#[must_use]
pub fn precision_value(&self) -> Option<u8> {
match self {
Self::SmallInt => Some(5_u8),
Self::Int => Some(10_u8),
Expand All @@ -313,7 +320,8 @@ impl ColumnType {
}
}
/// Returns scale of a ColumnType if it is convertible to a decimal wrapped in Some(). Otherwise return None.
#[must_use] pub fn scale(&self) -> Option<i8> {
#[must_use]
pub fn scale(&self) -> Option<i8> {
match self {
Self::Decimal75(_, scale) => Some(*scale),
Self::SmallInt | Self::Int | Self::BigInt | Self::Int128 | Self::Scalar => Some(0),
Expand All @@ -328,7 +336,8 @@ impl ColumnType {
}

/// Returns the byte size of the column type.
#[must_use] pub fn byte_size(&self) -> usize {
#[must_use]
pub fn byte_size(&self) -> usize {
match self {
Self::Boolean => size_of::<bool>(),
Self::SmallInt => size_of::<i16>(),
Expand All @@ -340,12 +349,14 @@ impl ColumnType {
}

/// Returns the bit size of the column type.
#[must_use] pub fn bit_size(&self) -> u32 {
#[must_use]
pub fn bit_size(&self) -> u32 {
self.byte_size() as u32 * 8
}

/// Returns if the column type supports signed values.
#[must_use] pub const fn is_signed(&self) -> bool {
#[must_use]
pub const fn is_signed(&self) -> bool {
match self {
Self::SmallInt | Self::Int | Self::BigInt | Self::Int128 | Self::TimestampTZ(_, _) => {
true
Expand Down Expand Up @@ -452,7 +463,8 @@ pub struct ColumnRef {

impl ColumnRef {
/// Create a new `ColumnRef` from a table, column identifier and column type
#[must_use] pub fn new(table_ref: TableRef, column_id: Identifier, column_type: ColumnType) -> Self {
#[must_use]
pub fn new(table_ref: TableRef, column_id: Identifier, column_type: ColumnType) -> Self {
Self {
column_id,
column_type,
Expand All @@ -461,17 +473,20 @@ impl ColumnRef {
}

/// Returns the table reference of this column
#[must_use] pub fn table_ref(&self) -> TableRef {
#[must_use]
pub fn table_ref(&self) -> TableRef {
self.table_ref
}

/// Returns the column identifier of this column
#[must_use] pub fn column_id(&self) -> Identifier {
#[must_use]
pub fn column_id(&self) -> Identifier {
self.column_id
}

/// Returns the column type of this column
#[must_use] pub fn column_type(&self) -> &ColumnType {
#[must_use]
pub fn column_type(&self) -> &ColumnType {
&self.column_type
}
}
Expand All @@ -488,17 +503,20 @@ pub struct ColumnField {

impl ColumnField {
/// Create a new `ColumnField` from a name and a type
#[must_use] pub fn new(name: Identifier, data_type: ColumnType) -> ColumnField {
#[must_use]
pub fn new(name: Identifier, data_type: ColumnType) -> ColumnField {
ColumnField { name, data_type }
}

/// Returns the name of the column
#[must_use] pub fn name(&self) -> Identifier {
#[must_use]
pub fn name(&self) -> Identifier {
self.name
}

/// Returns the type of the column
#[must_use] pub fn data_type(&self) -> ColumnType {
#[must_use]
pub fn data_type(&self) -> ColumnType {
self.data_type
}
}
Expand Down
12 changes: 8 additions & 4 deletions crates/proof-of-sql/src/base/database/owned_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ pub enum OwnedColumn<S: Scalar> {

impl<S: Scalar> OwnedColumn<S> {
/// Returns the length of the column.
#[must_use] pub fn len(&self) -> usize {
#[must_use]
pub fn len(&self) -> usize {
match self {
OwnedColumn::Boolean(col) => col.len(),
OwnedColumn::SmallInt(col) => col.len(),
Expand Down Expand Up @@ -80,7 +81,8 @@ impl<S: Scalar> OwnedColumn<S> {
}

/// Returns the sliced column.
#[must_use] pub fn slice(&self, start: usize, end: usize) -> Self {
#[must_use]
pub fn slice(&self, start: usize, end: usize) -> Self {
match self {
OwnedColumn::Boolean(col) => OwnedColumn::Boolean(col[start..end].to_vec()),
OwnedColumn::SmallInt(col) => OwnedColumn::SmallInt(col[start..end].to_vec()),
Expand All @@ -99,7 +101,8 @@ impl<S: Scalar> OwnedColumn<S> {
}

/// Returns true if the column is empty.
#[must_use] pub fn is_empty(&self) -> bool {
#[must_use]
pub fn is_empty(&self) -> bool {
match self {
OwnedColumn::Boolean(col) => col.is_empty(),
OwnedColumn::SmallInt(col) => col.is_empty(),
Expand All @@ -113,7 +116,8 @@ impl<S: Scalar> OwnedColumn<S> {
}
}
/// Returns the type of the column.
#[must_use] pub fn column_type(&self) -> ColumnType {
#[must_use]
pub fn column_type(&self) -> ColumnType {
match self {
OwnedColumn::Boolean(_) => ColumnType::Boolean,
OwnedColumn::SmallInt(_) => ColumnType::SmallInt,
Expand Down
15 changes: 10 additions & 5 deletions crates/proof-of-sql/src/base/database/owned_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,27 +39,32 @@ impl<S: Scalar> OwnedTable<S> {
Self::try_new(IndexMap::from_iter(iter))
}
/// Number of columns in the table.
#[must_use] pub fn num_columns(&self) -> usize {
#[must_use]
pub fn num_columns(&self) -> usize {
self.table.len()
}
/// Number of rows in the table.
#[must_use] pub fn num_rows(&self) -> usize {
#[must_use]
pub fn num_rows(&self) -> usize {
if self.table.is_empty() {
0
} else {
self.table[0].len()
}
}
/// Whether the table has no columns.
#[must_use] pub fn is_empty(&self) -> bool {
#[must_use]
pub fn is_empty(&self) -> bool {
self.table.is_empty()
}
/// Returns the columns of this table as an IndexMap
#[must_use] pub fn into_inner(self) -> IndexMap<Identifier, OwnedColumn<S>> {
#[must_use]
pub fn into_inner(self) -> IndexMap<Identifier, OwnedColumn<S>> {
self.table
}
/// Returns the columns of this table as an IndexMap
#[must_use] pub fn inner_table(&self) -> &IndexMap<Identifier, OwnedColumn<S>> {
#[must_use]
pub fn inner_table(&self) -> &IndexMap<Identifier, OwnedColumn<S>> {
&self.table
}
/// Returns the columns of this table as an Iterator
Expand Down
Loading

0 comments on commit 42ccf90

Please sign in to comment.