File tree Expand file tree Collapse file tree 1 file changed +5
-1
lines changed
library/src/scala/collection/mutable Expand file tree Collapse file tree 1 file changed +5
-1
lines changed Original file line number Diff line number Diff line change @@ -99,7 +99,11 @@ sealed class PriorityQueue[A](implicit val ord: Ordering[A])
99
99
100
100
private val resarr = new ResizableArrayAccess [A ]
101
101
102
- resarr.p_size0 += 1 // we do not use array(0) TODO: explain -- what is the first element even for?
102
+ // we do not use array(0)
103
+ // storing the root of the heap at array(1) simplifies the calculations for
104
+ // parent and child indices: for a given index k, the parent of k is k / 2,
105
+ // the left child is k * 2, and the right child is k * 2 + 1
106
+ resarr.p_size0 += 1
103
107
def length : Int = resarr.length - 1 // adjust length accordingly
104
108
override def size : Int = length
105
109
override def knownSize : Int = length
You can’t perform that action at this time.
0 commit comments