snarkvm_circuit_program/data/future/
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 Future<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        // Ensure the `arguments` are the same length.
24        if self.arguments.len() != other.arguments.len() {
25            return Boolean::constant(false);
26        }
27
28        // Recursively check each argument for equality.
29        let mut equal = Boolean::constant(true);
30        for (argument_a, argument_b) in self.arguments.iter().zip_eq(other.arguments.iter()) {
31            equal &= argument_a.is_equal(argument_b);
32        }
33
34        // Check the `program_id`, `function_name`, and arguments are equal.
35        self.program_id.is_equal(&other.program_id) & self.function_name.is_equal(&other.function_name) & equal
36    }
37
38    /// Returns `true` if `self` and `other` are *not* equal.
39    fn is_not_equal(&self, other: &Self) -> Self::Output {
40        // Check the `arguments` lengths.
41        if self.arguments.len() != other.arguments.len() {
42            return Boolean::constant(true);
43        }
44
45        // Recursively check each argument for equality.
46        let mut not_equal = Boolean::constant(false);
47        for (argument_a, argument_b) in self.arguments.iter().zip_eq(other.arguments.iter()) {
48            not_equal |= argument_a.is_not_equal(argument_b);
49        }
50
51        // Check the `program_id`, `function_name`, or arguments are not equal.
52        self.program_id.is_not_equal(&other.program_id)
53            | self.function_name.is_not_equal(&other.function_name)
54            | not_equal
55    }
56}