snarkvm_console_program/data/literal/
equal.rs1use super::*;
17
18impl<N: Network> Eq for Literal<N> {}
19
20impl<N: Network> PartialEq for Literal<N> {
21 fn eq(&self, other: &Self) -> bool {
23 *self.is_equal(other)
24 }
25}
26
27impl<N: Network> core::hash::Hash for Literal<N> {
28 fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
29 match self {
30 Self::Address(a) => a.hash(state),
31 Self::Boolean(a) => a.hash(state),
32 Self::Field(a) => a.hash(state),
33 Self::Group(a) => a.hash(state),
34 Self::I8(a) => a.hash(state),
35 Self::I16(a) => a.hash(state),
36 Self::I32(a) => a.hash(state),
37 Self::I64(a) => a.hash(state),
38 Self::I128(a) => a.hash(state),
39 Self::U8(a) => a.hash(state),
40 Self::U16(a) => a.hash(state),
41 Self::U32(a) => a.hash(state),
42 Self::U64(a) => a.hash(state),
43 Self::U128(a) => a.hash(state),
44 Self::Scalar(a) => a.hash(state),
45 Self::Signature(a) => a.hash(state),
46 Self::String(a) => a.hash(state),
47 }
48 }
49}
50
51impl<N: Network> Equal for Literal<N> {
52 type Output = Boolean<N>;
53
54 fn is_equal(&self, other: &Self) -> Self::Output {
56 match (self, other) {
57 (Self::Address(a), Self::Address(b)) => a.is_equal(b),
58 (Self::Boolean(a), Self::Boolean(b)) => a.is_equal(b),
59 (Self::Field(a), Self::Field(b)) => a.is_equal(b),
60 (Self::Group(a), Self::Group(b)) => a.is_equal(b),
61 (Self::I8(a), Self::I8(b)) => a.is_equal(b),
62 (Self::I16(a), Self::I16(b)) => a.is_equal(b),
63 (Self::I32(a), Self::I32(b)) => a.is_equal(b),
64 (Self::I64(a), Self::I64(b)) => a.is_equal(b),
65 (Self::I128(a), Self::I128(b)) => a.is_equal(b),
66 (Self::U8(a), Self::U8(b)) => a.is_equal(b),
67 (Self::U16(a), Self::U16(b)) => a.is_equal(b),
68 (Self::U32(a), Self::U32(b)) => a.is_equal(b),
69 (Self::U64(a), Self::U64(b)) => a.is_equal(b),
70 (Self::U128(a), Self::U128(b)) => a.is_equal(b),
71 (Self::Scalar(a), Self::Scalar(b)) => a.is_equal(b),
72 (Self::Signature(a), Self::Signature(b)) => a.is_equal(b),
73 (Self::String(a), Self::String(b)) => a.is_equal(b),
74 _ => Boolean::new(false),
75 }
76 }
77
78 fn is_not_equal(&self, other: &Self) -> Self::Output {
80 match (self, other) {
81 (Self::Address(a), Self::Address(b)) => a.is_not_equal(b),
82 (Self::Boolean(a), Self::Boolean(b)) => a.is_not_equal(b),
83 (Self::Field(a), Self::Field(b)) => a.is_not_equal(b),
84 (Self::Group(a), Self::Group(b)) => a.is_not_equal(b),
85 (Self::I8(a), Self::I8(b)) => a.is_not_equal(b),
86 (Self::I16(a), Self::I16(b)) => a.is_not_equal(b),
87 (Self::I32(a), Self::I32(b)) => a.is_not_equal(b),
88 (Self::I64(a), Self::I64(b)) => a.is_not_equal(b),
89 (Self::I128(a), Self::I128(b)) => a.is_not_equal(b),
90 (Self::U8(a), Self::U8(b)) => a.is_not_equal(b),
91 (Self::U16(a), Self::U16(b)) => a.is_not_equal(b),
92 (Self::U32(a), Self::U32(b)) => a.is_not_equal(b),
93 (Self::U64(a), Self::U64(b)) => a.is_not_equal(b),
94 (Self::U128(a), Self::U128(b)) => a.is_not_equal(b),
95 (Self::Scalar(a), Self::Scalar(b)) => a.is_not_equal(b),
96 (Self::Signature(a), Self::Signature(b)) => a.is_not_equal(b),
97 (Self::String(a), Self::String(b)) => a.is_not_equal(b),
98 _ => Boolean::new(true),
99 }
100 }
101}