Skip to content

Commit cfea944

Browse files
committed
partition: Minor cleanup
Add a safety assertion to cluster adjacency build to make sure our space estimation logic worked, and use a slightly shorter and less branchy heap child selection.
1 parent 2e06eba commit cfea944

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/partition.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ static void buildClusterAdjacency(ClusterAdjacency& adjacency, const unsigned in
155155
adjacency.offsets[i + 1] = adjacency.offsets[i] + unsigned(count);
156156
}
157157

158+
assert(adjacency.offsets[cluster_count] <= total_adjacency);
159+
158160
// ref_offsets can't be deallocated as it was allocated before adjacency
159161
allocator.deallocate(ref_data);
160162
}
@@ -205,8 +207,7 @@ static GroupOrder heapPop(GroupOrder* heap, size_t size)
205207
{
206208
// find the smallest child
207209
size_t j = i * 2 + 1;
208-
if (j + 1 < size && heap[j + 1].order < heap[j].order)
209-
j++;
210+
j += (j + 1 < size && heap[j + 1].order < heap[j].order);
210211

211212
// if the parent is already smaller than both children, we're done
212213
if (heap[j].order >= heap[i].order)

0 commit comments

Comments
 (0)