1 |
/* PriorityQueue.java -- Unbounded priority queue |
/* PriorityQueue.java -- Unbounded priority queue |
2 |
Copyright (C) 2004 Free Software Foundation, Inc. |
Copyright (C) 2004, 2005 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
39 |
package java.util; |
package java.util; |
40 |
|
|
41 |
/** |
/** |
42 |
|
* @author Tom Tromey (tromey@redhat.com) |
43 |
|
* @author Andrew John Hughes (gnu_andrew@member.fsf.org) |
44 |
* @since 1.5 |
* @since 1.5 |
45 |
*/ |
*/ |
46 |
public class PriorityQueue<E> extends AbstractQueue<E> |
public class PriorityQueue<E> extends AbstractQueue<E> |
73 |
this(Math.max(1, (int) (1.1 * c.size())), null); |
this(Math.max(1, (int) (1.1 * c.size())), null); |
74 |
|
|
75 |
// Special case where we can find the comparator to use. |
// Special case where we can find the comparator to use. |
76 |
if (c instanceof SortedSet<? extends E>) |
if (c instanceof SortedSet) |
77 |
{ |
{ |
78 |
SortedSet<? extends E> ss = (SortedSet<? extends E>) c; |
SortedSet<? extends E> ss = (SortedSet<? extends E>) c; |
79 |
this.comparator = ss.comparator(); |
this.comparator = ss.comparator(); |
86 |
storage[i++] = val; |
storage[i++] = val; |
87 |
} |
} |
88 |
} |
} |
89 |
else if (c instanceof PriorityQueue<? extends E>) |
else if (c instanceof PriorityQueue) |
90 |
{ |
{ |
91 |
PriorityQueue<? extends E> pq = (PriorityQueue<? extends E>) c; |
PriorityQueue<? extends E> pq = (PriorityQueue<? extends E>) c; |
92 |
this.comparator = pq.comparator(); |
this.comparator = pq.comparator(); |
105 |
public PriorityQueue(int cap, Comparator<? super E> comp) |
public PriorityQueue(int cap, Comparator<? super E> comp) |
106 |
{ |
{ |
107 |
this.used = 0; |
this.used = 0; |
108 |
this.storage = new E[cap]; |
this.storage = (E[]) new Object[cap]; |
109 |
this.comparator = comp; |
this.comparator = comp; |
110 |
} |
} |
111 |
|
|
160 |
return storage[index]; |
return storage[index]; |
161 |
} |
} |
162 |
|
|
163 |
void remove() |
public void remove() |
164 |
{ |
{ |
165 |
remove(index); |
PriorityQueue.this.remove(index); |
166 |
} |
} |
167 |
}; |
}; |
168 |
} |
} |
319 |
|
|
320 |
void resize() |
void resize() |
321 |
{ |
{ |
322 |
E[] new_data = new E[2 * storage.length]; |
E[] new_data = (E[]) new Object[2 * storage.length]; |
323 |
System.arraycopy(storage, 0, new_data, 0, storage.length); |
System.arraycopy(storage, 0, new_data, 0, storage.length); |
324 |
storage = new_data; |
storage = new_data; |
325 |
} |
} |