We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent b195cbc commit ccdadefCopy full SHA for ccdadef
src/k_smallest.rs
@@ -124,12 +124,15 @@ where
124
}
125
126
let (left_idx, right_idx) = children_of(origin);
127
- let (left_item, right_item) = (self.get(left_idx), self.get(right_idx));
128
129
- if left_item.is_none() { // the left is the earlier child, so if it doesn't exist there's nothing to swap with
+ if left_idx >= self.len {
+ // the left is the earlier child, so if it doesn't exist there's nothing to swap with
130
return;
131
132
133
+ let (left_item, right_item) = (self.get(left_idx), self.get(right_idx));
134
+
135
136
let cmp = self
137
.compare(left_item, right_item)
138
.unwrap_or(Ordering::Greater); // The right item may not exist, so default to picking the left, i.e. lower
0 commit comments