-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPQNode.java
More file actions
31 lines (25 loc) · 799 Bytes
/
PQNode.java
File metadata and controls
31 lines (25 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package examples;
import specification.Free;
import specification.Unique;
class PQNode {
// @Refinement("min(this) == value")
PQNode(int value, @Free PQNode next) {
this.value = value;
this.next = next;
}
int value;
//@Refinement("this.next == null || min(this.next) < this.value")
@Unique PQNode next;
// @Refinement(@Borrowed PQNode this, "min(this) <= v")
void insert(int v) {
if (v < this.value) {
PQNode nxt = this.next;
this.next = null;
PQNode newNode = new PQNode(this.value, nxt);
this.value = v;
this.next = newNode; // note: if we swap this with the statement above, the refinement is briefly violated
} else {
next.insert(v);
}
}
}