X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Fsrc%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Felaboration%2Fchr%2Fplanning%2FPlanPriorityQueue.java;h=df9229186a0c3d27a1a99047e8f52575688af8e7;hb=a2df536f7fc878982c6c960a79ed49f350cddc6f;hp=7eb8ae5f2062dad2196c36183eef0c68431be952;hpb=cb5fc8d606d8b322563e9345c441eecfa7f01753;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/planning/PlanPriorityQueue.java b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/planning/PlanPriorityQueue.java index 7eb8ae5f2..df9229186 100644 --- a/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/planning/PlanPriorityQueue.java +++ b/bundles/org.simantics.scl.compiler/src/org/simantics/scl/compiler/elaboration/chr/planning/PlanPriorityQueue.java @@ -1,86 +1,86 @@ -package org.simantics.scl.compiler.elaboration.chr.planning; - -import java.util.Arrays; - -public class PlanPriorityQueue { - PrePlanItem[] items = new PrePlanItem[16]; - int size = 0; - - public PrePlanItem head() { - return items[0]; - } - - public void pop() { - items[0].queuePos = -1; - --size; - if (size > 0) { - PrePlanItem e = items[size]; - items[0] = e; - e.queuePos = 0; - adjustDown(e); - } - items[size] = null; - } - - public void add(PrePlanItem e) { - if (size == items.length) - items = Arrays.copyOf(items, size + size / 2); - items[size] = e; - e.queuePos = size; - ++size; - adjustUp(e); - } - - private boolean adjustUp(PrePlanItem e) { - int pos = e.queuePos; - while (pos > 0) { - int upId = (pos - 1) / 2; - PrePlanItem upE = items[upId]; - if (e.compare(upE) >= 0) - break; - items[pos] = upE; - upE.queuePos = pos; - pos = upId; - } - if (e.queuePos != pos) { - items[pos] = e; - e.queuePos = pos; - return true; - } else - return false; - } - - private void adjustDown(PrePlanItem e) { - int pos = e.queuePos; - while (true) { - int downId = pos * 2 + 1; - if (downId >= size) - break; - if (downId + 1 < size - && items[downId].compare(items[downId + 1]) > 0) - ++downId; - PrePlanItem downE = items[downId]; - if (e.compare(downE) > 0) { - items[pos] = downE; - downE.queuePos = pos; - pos = downId; - } else - break; - } - if (e.queuePos != pos) { - items[pos] = e; - e.queuePos = pos; - } - } - - public void adjust(PrePlanItem e) { - if(e.queuePos == -1) - return; - if (!adjustUp(e)) - adjustDown(e); - } - - public boolean isEmpty() { - return size == 0; - } -} +package org.simantics.scl.compiler.elaboration.chr.planning; + +import java.util.Arrays; + +public class PlanPriorityQueue { + PrePlanItem[] items = new PrePlanItem[16]; + int size = 0; + + public PrePlanItem head() { + return items[0]; + } + + public void pop() { + items[0].queuePos = -1; + --size; + if (size > 0) { + PrePlanItem e = items[size]; + items[0] = e; + e.queuePos = 0; + adjustDown(e); + } + items[size] = null; + } + + public void add(PrePlanItem e) { + if (size == items.length) + items = Arrays.copyOf(items, size + size / 2); + items[size] = e; + e.queuePos = size; + ++size; + adjustUp(e); + } + + private boolean adjustUp(PrePlanItem e) { + int pos = e.queuePos; + while (pos > 0) { + int upId = (pos - 1) / 2; + PrePlanItem upE = items[upId]; + if (e.compare(upE) >= 0) + break; + items[pos] = upE; + upE.queuePos = pos; + pos = upId; + } + if (e.queuePos != pos) { + items[pos] = e; + e.queuePos = pos; + return true; + } else + return false; + } + + private void adjustDown(PrePlanItem e) { + int pos = e.queuePos; + while (true) { + int downId = pos * 2 + 1; + if (downId >= size) + break; + if (downId + 1 < size + && items[downId].compare(items[downId + 1]) > 0) + ++downId; + PrePlanItem downE = items[downId]; + if (e.compare(downE) > 0) { + items[pos] = downE; + downE.queuePos = pos; + pos = downId; + } else + break; + } + if (e.queuePos != pos) { + items[pos] = e; + e.queuePos = pos; + } + } + + public void adjust(PrePlanItem e) { + if(e.queuePos == -1) + return; + if (!adjustUp(e)) + adjustDown(e); + } + + public boolean isEmpty() { + return size == 0; + } +}