File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -89,6 +89,20 @@ struct RangeImpl {
8989 func prettyprint() {
9090 return "Range from={0} to={1}".format(this.from, this.to);
9191 }
92+
93+ func hash() {
94+ val h = this.from ^ (this.to + 0xe3779b97f4a7c15);
95+ h = h ^ (h >> 30);
96+ h = h * 0xf58476d1ce4e5b9;
97+ h = h ^ (h >> 27);
98+ h = h * 0x4d049bb133111eb;
99+ h = h ^ (h >> 31);
100+ return h;
101+ }
102+
103+ operator == (other: RangeImpl) {
104+ return this.from == other.from && this.to == other.to;
105+ }
92106}
93107
94108struct RangeFrom {
Original file line number Diff line number Diff line change 1+ # SPDX-License-Identifier: Apache-2.0
2+ import Range from aria.range.range;
3+
4+ func main() {
5+ val r1 = Range.from(5).to(10);
6+ val r2 = Range.from(6).to(10);
7+ val r3 = Range.from(5).to(11);
8+
9+ assert r1.hash() != r2.hash();
10+ assert r1.hash() != r3.hash();
11+ assert r2.hash() != r3.hash();
12+
13+ assert r1.hash() == r1.hash();
14+ assert r2.hash() == r2.hash();
15+ assert r3.hash() == r3.hash();
16+
17+ val r4 = Range.from(6).to(10);
18+
19+ assert r4.hash() == r2.hash();
20+ assert r2 == r4;
21+ }
You can’t perform that action at this time.
0 commit comments