@@ -12,11 +12,11 @@ import library "io_utils";
1212// A three-element sliding window of recent levels.
1313class Window {
1414 fn Make () - > Window { return {.data = (0 ,0 ,0 ), .size = 0 }; }
15- fn Add[addr self: Self* ](n: i32 ) {
16- self- > data[2 ] = self- > data[1 ];
17- self- > data[1 ] = self- > data[0 ];
18- self- > data[0 ] = n;
19- ++ self- > size;
15+ fn Add[ref self: Self](n: i32 ) {
16+ self. data[2 ] = self. data[1 ];
17+ self. data[1 ] = self. data[0 ];
18+ self. data[0 ] = n;
19+ ++ self. size;
2020 }
2121
2222 var data: array (i32 , 3 );
@@ -36,7 +36,7 @@ class ReportState {
3636 .removable_double_bad_edge = false };
3737 }
3838
39- fn OnAdd[addr self: Self* ](window: Window) {
39+ fn OnAdd[ref self: Self](window: Window) {
4040 if (window.size < 2 ) {
4141 return ;
4242 }
@@ -47,39 +47,39 @@ class ReportState {
4747 let c: i32 = window.data[0 ];
4848
4949 // Keep a count of the unsafe edges.
50- let b_to_c: bool = IsSafe (window.data[1 ], window.data[0 ], self- > increasing);
50+ let b_to_c: bool = IsSafe (window.data[1 ], window.data[0 ], self. increasing);
5151 if (not b_to_c) {
52- ++ self- > bad_edges;
52+ ++ self. bad_edges;
5353
5454 // We have a removable single bad edge if the first edge is unsafe.
5555 if (window.size == 2 ) {
56- self- > removable_single_bad_edge = true ;
56+ self. removable_single_bad_edge = true ;
5757 }
5858 }
5959
6060 if (window.size > = 3 ) {
6161 let a: i32 = window.data[2 ];
62- if (IsSafe (a, c, self- > increasing)) {
63- let lhs: bool = IsSafe (a, b, self- > increasing);
62+ if (IsSafe (a, c, self. increasing)) {
63+ let lhs: bool = IsSafe (a, b, self. increasing);
6464 let rhs: bool = b_to_c;
6565 if (not lhs and not rhs) {
6666 // If a->b and b->c are both unsafe, but a->c is safe,
6767 // then we have a removable double bad edge.
68- self- > removable_double_bad_edge = true ;
68+ self. removable_double_bad_edge = true ;
6969 } else if (not lhs or not rhs) {
7070 // If a->b or b->c is unsafe but a->c is safe, then we have a
7171 // removable single bad edge.
72- self- > removable_single_bad_edge = true ;
72+ self. removable_single_bad_edge = true ;
7373 }
7474 }
7575 }
7676 }
7777
78- fn OnFinish[addr self: Self* ](window: Window) {
78+ fn OnFinish[ref self: Self](window: Window) {
7979 if (window.size > = 2 and
80- not IsSafe (window.data[1 ], window.data[0 ], self- > increasing)) {
80+ not IsSafe (window.data[1 ], window.data[0 ], self. increasing)) {
8181 // We have a removable single bad edge if the last edge is unsafe.
82- self- > removable_single_bad_edge = true ;
82+ self. removable_single_bad_edge = true ;
8383 }
8484 }
8585
0 commit comments