[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Gzz-commits] gzz doc/Gzz_Memory.rst gzz/util/PriorityQueue.j...
From: |
Tuomas J. Lukka |
Subject: |
[Gzz-commits] gzz doc/Gzz_Memory.rst gzz/util/PriorityQueue.j... |
Date: |
Fri, 10 Jan 2003 14:23:37 -0500 |
CVSROOT: /cvsroot/gzz
Module name: gzz
Changes by: Tuomas J. Lukka <address@hidden> 03/01/10 14:23:37
Modified files:
doc : Gzz_Memory.rst
gzz/util : PriorityQueue.java
Added files:
test/gzz/util : priorityqueue.test
Log message:
Implement and test priorityqueue
CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/doc/Gzz_Memory.rst.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/gzz/util/PriorityQueue.java.diff?tr1=1.2&tr2=1.3&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/gzz/gzz/test/gzz/util/priorityqueue.test?rev=1.1
Patches:
Index: gzz/doc/Gzz_Memory.rst
diff -u gzz/doc/Gzz_Memory.rst:1.9 gzz/doc/Gzz_Memory.rst:1.10
--- gzz/doc/Gzz_Memory.rst:1.9 Thu Jan 9 07:11:56 2003
+++ gzz/doc/Gzz_Memory.rst Fri Jan 10 14:23:32 2003
@@ -164,9 +164,9 @@
int getMaxBytes(float quality)
void setReservation(priority, bytes, quality, Obs o)
- dep "use" TextureImageMemoryConsumer gzz.util.BackgroundThread
+ dep "use" TextureImageMemoryConsumer gzz.util.Background
- class gzz.util.BackgroundThread
+ class gzz.util.Background
methods
void addTask(Runnable r, int priority)
assoc role(loader) multi(1) - multi(1) MemoryPartitioner
@@ -177,7 +177,7 @@
vertically(60, aaa, MemoryPartitioner, MemoryConsumer,
TextureImageMemoryConsumer);
pagequal.w = GLSpanner.e;
- horizontally(60, bbb, pagequal, TextureImageMemoryConsumer,
gzz.util.BackgroundThread);
+ horizontally(60, bbb, pagequal, TextureImageMemoryConsumer,
gzz.util.Background);
gzz.mem.nw = MemoryPartitioner.nw + (-30, 30);
gzz.mem.se = MemoryConsumer.se + (30, -30);
Index: gzz/gzz/util/PriorityQueue.java
diff -u gzz/gzz/util/PriorityQueue.java:1.2 gzz/gzz/util/PriorityQueue.java:1.3
--- gzz/gzz/util/PriorityQueue.java:1.2 Fri Jan 10 13:55:40 2003
+++ gzz/gzz/util/PriorityQueue.java Fri Jan 10 14:23:34 2003
@@ -12,18 +12,60 @@
public class PriorityQueue {
+ /** Compare two objects using the jobPriority value
+ * as primary and hash code as secondary code.
+ */
+ private class Comp implements Comparator {
+ public int compare(Object o1, Object o2) {
+ Integer p1 = (Integer)jobPriority.get(o1);
+ Integer p2 = (Integer)jobPriority.get(o2);
+ int i1 = p1.intValue();
+ int i2 = p2.intValue();
+ if(i1 < i2) return -1;
+ if(i1 > i2) return 1;
+ i1 = o1.hashCode();
+ i2 = o2.hashCode();
+ if(i1 < i2) return -1;
+ if(i1 > i2) return 1;
+ return 0;
+ }
+ }
+
+ /** Job object to Integer (the priority).
+ */
private Map jobPriority = new HashMap();
- private TreeSet jobs = new TreeSet();
+ /** Set of jobs, to be compared by their priorities.
+ */
+ private TreeSet jobs = new TreeSet(new Comp());
+
/** Add a job to run.
* If the job has already been added, set the priority
* to the lower value (more important) of the two.
*/
public synchronized void add(Object job, int priority) {
+ Integer prevprio = (Integer)jobPriority.get(job);
+ if(prevprio != null) {
+ if(priority >= prevprio.intValue()) return;
+ // Now, in order not to corrupt the TreeSet,
+ // we must FIRST remove the element, then change
+ // the priority and then re-add it after the priority
+ // has been changed.
+ jobs.remove(job);
+ }
+ jobPriority.put(job, new Integer(priority));
+ jobs.add(job);
}
+ /** Get the most important (with lowest numeric priority) job and remove
+ * it from this queue.
+ */
public synchronized Object getAndRemoveLowest() {
- return null;
+ if(jobs.isEmpty()) return null;
+ Object j = jobs.first();
+ jobs.remove(j);
+ jobPriority.remove(j);
+ return j;
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Gzz-commits] gzz doc/Gzz_Memory.rst gzz/util/PriorityQueue.j...,
Tuomas J. Lukka <=