diff --git a/drv/HeapPriorityQueue.drv b/drv/HeapPriorityQueue.drv index 7570d3d33..ae3961617 100644 --- a/drv/HeapPriorityQueue.drv +++ b/drv/HeapPriorityQueue.drv @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2024 Paolo Boldi and Sebastiano Vigna + * Copyright (C) 2003-2025 Paolo Boldi and Sebastiano Vigna * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -14,7 +14,6 @@ * limitations under the License. */ - package PACKAGE; #if KEY_CLASS_Object @@ -29,13 +28,11 @@ import java.util.Iterator; import java.util.Collection; import java.util.NoSuchElementException; - /** A type-specific heap-based priority queue. * *
Instances of this class represent a priority queue using a heap. The heap is enlarged as needed, but * it is never shrunk. Use the {@link #trim()} method to reduce its size, if necessary. */ - public class HEAP_PRIORITY_QUEUE KEY_GENERIC implements PRIORITY_QUEUE KEY_GENERIC, java.io.Serializable { private static final long serialVersionUID = 1L; @@ -278,6 +275,29 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC implements PRIORITY_QUEUE KEY_GENER for(int i = 0; i < size; i++) heap[i] = KEY_GENERIC_CAST s.READ_KEY(); } + /** Returns the physical capacity of the queue (internal array). */ + public int capacity() { + return heap.length; + } + + /** @see java.util.Collection#toArray() */ + public KEY_GENERIC_TYPE[] toArray() { + return ARRAYS.copy(heap, 0, size()); + } + + @Override + public String toString() { + int iMax = size() - 1; + if (iMax == -1) return "[]"; + StringBuilder sb = new StringBuilder(iMax*9+9).append('['); + for (int i = 0; ; i++){ + sb.append(heap[i]); + if (i == iMax){ + return sb.append(']').toString(); + } + sb.append(", "); + } + } #ifdef TEST @@ -500,4 +520,4 @@ public class HEAP_PRIORITY_QUEUE KEY_GENERIC implements PRIORITY_QUEUE KEY_GENER #endif -} +} \ No newline at end of file