snarkvm_circuit_program/data/literal/
equal.rs

1// Copyright (c) 2019-2025 Provable Inc.
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7
8// http://www.apache.org/licenses/LICENSE-2.0
9
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15
16use super::*;
17
18impl<A: Aleo> Equal<Self> for Literal<A> {
19    type Output = Boolean<A>;
20
21    /// Returns `true` if `self` and `other` are equal.
22    fn is_equal(&self, other: &Self) -> Self::Output {
23        match (self, other) {
24            (Self::Address(a), Self::Address(b)) => a.is_equal(b),
25            (Self::Boolean(a), Self::Boolean(b)) => a.is_equal(b),
26            (Self::Field(a), Self::Field(b)) => a.is_equal(b),
27            (Self::Group(a), Self::Group(b)) => a.is_equal(b),
28            (Self::I8(a), Self::I8(b)) => a.is_equal(b),
29            (Self::I16(a), Self::I16(b)) => a.is_equal(b),
30            (Self::I32(a), Self::I32(b)) => a.is_equal(b),
31            (Self::I64(a), Self::I64(b)) => a.is_equal(b),
32            (Self::I128(a), Self::I128(b)) => a.is_equal(b),
33            (Self::U8(a), Self::U8(b)) => a.is_equal(b),
34            (Self::U16(a), Self::U16(b)) => a.is_equal(b),
35            (Self::U32(a), Self::U32(b)) => a.is_equal(b),
36            (Self::U64(a), Self::U64(b)) => a.is_equal(b),
37            (Self::U128(a), Self::U128(b)) => a.is_equal(b),
38            (Self::Scalar(a), Self::Scalar(b)) => a.is_equal(b),
39            (Self::Signature(a), Self::Signature(b)) => a.is_equal(b),
40            (Self::String(a), Self::String(b)) => a.is_equal(b),
41            _ => Boolean::constant(false),
42        }
43    }
44
45    /// Returns `true` if `self` and `other` are *not* equal.
46    fn is_not_equal(&self, other: &Self) -> Self::Output {
47        match (self, other) {
48            (Self::Address(a), Self::Address(b)) => a.is_not_equal(b),
49            (Self::Boolean(a), Self::Boolean(b)) => a.is_not_equal(b),
50            (Self::Field(a), Self::Field(b)) => a.is_not_equal(b),
51            (Self::Group(a), Self::Group(b)) => a.is_not_equal(b),
52            (Self::I8(a), Self::I8(b)) => a.is_not_equal(b),
53            (Self::I16(a), Self::I16(b)) => a.is_not_equal(b),
54            (Self::I32(a), Self::I32(b)) => a.is_not_equal(b),
55            (Self::I64(a), Self::I64(b)) => a.is_not_equal(b),
56            (Self::I128(a), Self::I128(b)) => a.is_not_equal(b),
57            (Self::U8(a), Self::U8(b)) => a.is_not_equal(b),
58            (Self::U16(a), Self::U16(b)) => a.is_not_equal(b),
59            (Self::U32(a), Self::U32(b)) => a.is_not_equal(b),
60            (Self::U64(a), Self::U64(b)) => a.is_not_equal(b),
61            (Self::U128(a), Self::U128(b)) => a.is_not_equal(b),
62            (Self::Scalar(a), Self::Scalar(b)) => a.is_not_equal(b),
63            (Self::Signature(a), Self::Signature(b)) => a.is_not_equal(b),
64            (Self::String(a), Self::String(b)) => a.is_not_equal(b),
65            _ => Boolean::constant(true),
66        }
67    }
68}