/ console / program / src / data / literal / equal.rs
equal.rs
  1  // Copyright (c) 2025-2026 ACDC Network
  2  // This file is part of the alphavm library.
  3  //
  4  // Alpha Chain | Delta Chain Protocol
  5  // International Monetary Graphite.
  6  //
  7  // Derived from Aleo (https://aleo.org) and ProvableHQ (https://provable.com).
  8  // They built world-class ZK infrastructure. We installed the EASY button.
  9  // Their cryptography: elegant. Our modifications: bureaucracy-compatible.
 10  // Original brilliance: theirs. Robert's Rules: ours. Bugs: definitely ours.
 11  //
 12  // Original Aleo/ProvableHQ code subject to Apache 2.0 https://www.apache.org/licenses/LICENSE-2.0
 13  // All modifications and new work: CC0 1.0 Universal Public Domain Dedication.
 14  // No rights reserved. No permission required. No warranty. No refunds.
 15  //
 16  // https://creativecommons.org/publicdomain/zero/1.0/
 17  // SPDX-License-Identifier: CC0-1.0
 18  
 19  use super::*;
 20  
 21  impl<N: Network> Eq for Literal<N> {}
 22  
 23  impl<N: Network> PartialEq for Literal<N> {
 24      /// Returns `true` if `self` and `other` are equal.
 25      fn eq(&self, other: &Self) -> bool {
 26          *self.is_equal(other)
 27      }
 28  }
 29  
 30  impl<N: Network> core::hash::Hash for Literal<N> {
 31      fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
 32          match self {
 33              Self::Address(a) => a.hash(state),
 34              Self::Boolean(a) => a.hash(state),
 35              Self::Field(a) => a.hash(state),
 36              Self::Group(a) => a.hash(state),
 37              Self::I8(a) => a.hash(state),
 38              Self::I16(a) => a.hash(state),
 39              Self::I32(a) => a.hash(state),
 40              Self::I64(a) => a.hash(state),
 41              Self::I128(a) => a.hash(state),
 42              Self::U8(a) => a.hash(state),
 43              Self::U16(a) => a.hash(state),
 44              Self::U32(a) => a.hash(state),
 45              Self::U64(a) => a.hash(state),
 46              Self::U128(a) => a.hash(state),
 47              Self::Scalar(a) => a.hash(state),
 48              Self::Signature(a) => a.hash(state),
 49              Self::String(a) => a.hash(state),
 50          }
 51      }
 52  }
 53  
 54  impl<N: Network> Equal for Literal<N> {
 55      type Output = Boolean<N>;
 56  
 57      /// Returns `true` if `self` and `other` are equal.
 58      fn is_equal(&self, other: &Self) -> Self::Output {
 59          match (self, other) {
 60              (Self::Address(a), Self::Address(b)) => a.is_equal(b),
 61              (Self::Boolean(a), Self::Boolean(b)) => a.is_equal(b),
 62              (Self::Field(a), Self::Field(b)) => a.is_equal(b),
 63              (Self::Group(a), Self::Group(b)) => a.is_equal(b),
 64              (Self::I8(a), Self::I8(b)) => a.is_equal(b),
 65              (Self::I16(a), Self::I16(b)) => a.is_equal(b),
 66              (Self::I32(a), Self::I32(b)) => a.is_equal(b),
 67              (Self::I64(a), Self::I64(b)) => a.is_equal(b),
 68              (Self::I128(a), Self::I128(b)) => a.is_equal(b),
 69              (Self::U8(a), Self::U8(b)) => a.is_equal(b),
 70              (Self::U16(a), Self::U16(b)) => a.is_equal(b),
 71              (Self::U32(a), Self::U32(b)) => a.is_equal(b),
 72              (Self::U64(a), Self::U64(b)) => a.is_equal(b),
 73              (Self::U128(a), Self::U128(b)) => a.is_equal(b),
 74              (Self::Scalar(a), Self::Scalar(b)) => a.is_equal(b),
 75              (Self::Signature(a), Self::Signature(b)) => a.is_equal(b),
 76              (Self::String(a), Self::String(b)) => a.is_equal(b),
 77              _ => Boolean::new(false),
 78          }
 79      }
 80  
 81      /// Returns `true` if `self` and `other` are *not* equal.
 82      fn is_not_equal(&self, other: &Self) -> Self::Output {
 83          match (self, other) {
 84              (Self::Address(a), Self::Address(b)) => a.is_not_equal(b),
 85              (Self::Boolean(a), Self::Boolean(b)) => a.is_not_equal(b),
 86              (Self::Field(a), Self::Field(b)) => a.is_not_equal(b),
 87              (Self::Group(a), Self::Group(b)) => a.is_not_equal(b),
 88              (Self::I8(a), Self::I8(b)) => a.is_not_equal(b),
 89              (Self::I16(a), Self::I16(b)) => a.is_not_equal(b),
 90              (Self::I32(a), Self::I32(b)) => a.is_not_equal(b),
 91              (Self::I64(a), Self::I64(b)) => a.is_not_equal(b),
 92              (Self::I128(a), Self::I128(b)) => a.is_not_equal(b),
 93              (Self::U8(a), Self::U8(b)) => a.is_not_equal(b),
 94              (Self::U16(a), Self::U16(b)) => a.is_not_equal(b),
 95              (Self::U32(a), Self::U32(b)) => a.is_not_equal(b),
 96              (Self::U64(a), Self::U64(b)) => a.is_not_equal(b),
 97              (Self::U128(a), Self::U128(b)) => a.is_not_equal(b),
 98              (Self::Scalar(a), Self::Scalar(b)) => a.is_not_equal(b),
 99              (Self::Signature(a), Self::Signature(b)) => a.is_not_equal(b),
100              (Self::String(a), Self::String(b)) => a.is_not_equal(b),
101              _ => Boolean::new(true),
102          }
103      }
104  }