1 package org.simantics.scl.runtime.chr;
4 * This class implements a pairing heap of CHR priorities.
6 public abstract class CHRPriority implements Comparable<CHRPriority> {
8 public final int priority;
11 private CHRPriority sibling;
12 private CHRPriority child;
16 public CHRPriority(int priority) {
17 this.priority = priority;
21 * This method assume that a and b are roots and their sibling field
24 public static CHRPriority merge(CHRPriority a, CHRPriority b) {
25 if(a.priority <= b.priority) {
39 protected void ensureInContext(CHRContext context) {
41 CHRPriority topPriority = context.topPriority;
42 if(topPriority == null)
43 context.topPriority = this;
45 context.topPriority = merge(topPriority, this);
50 private CHRPriority mergeSiblings() {
53 CHRPriority nextSibling = sibling.sibling;
54 CHRPriority merged = merge(this, sibling);
55 if(nextSibling == null)
58 return merge(merged, nextSibling.mergeSiblings());
61 public CHRPriority nextPriority() {
65 CHRPriority result = child.mergeSiblings();
72 public int compareTo(CHRPriority o) {
73 return Double.compare(priority, o.priority);
76 public abstract void activate(CHRContext context);
77 //public abstract CHRRuntimeRuleset getParent();