Skip to content

Commit 9c8ffb8

Browse files
committed
fixup kung
1 parent 4e1bf6a commit 9c8ffb8

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

c/nondominated.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,12 @@ find_nondominated_3d_impl_sorted(const double ** restrict rows, size_t size,
362362
avl_insert_after(&tree, node - 1, node);
363363

364364
// In this context, size means "no dominated solution found".
365-
size_t new_size = size, j = 1;
365+
size_t new_size = size, j = 1, k = 0;
366366
const double * last_dom = NULL;
367367
const double * restrict pk = rows[0];
368368
do {
369369
bool dominated;
370+
size_t pos_dom = j;
370371
const double * restrict pj = rows[j];
371372
DEBUG2(printf_point("pj = [ ", pj, 3, " ], "));
372373
if (pk[0] > pj[0] || pk[1] > pj[1]) {
@@ -416,8 +417,10 @@ find_nondominated_3d_impl_sorted(const double ** restrict rows, size_t size,
416417
const bool k_eq_j = (pk[0] == pj[0]) & (pk[1] == pj[1]) & (pk[2] == pj[2]);
417418
if (!keep_weakly) { // We don't keep duplicates;
418419
dominated = true;
419-
if (unlikely(k_eq_j) && pj < pk) // Only the first duplicated point is kept.
420-
SWAP(pk, pj);
420+
if (unlikely(k_eq_j) && pj < pk) { // Only the first duplicated point is kept.
421+
pos_dom = k;
422+
pj = pk;
423+
}
421424
} else { // or it is not a duplicate, so it is non-weakly dominated;
422425
dominated = likely(!k_eq_j)
423426
// or pk was dominated, then this one is also dominated.
@@ -428,14 +431,15 @@ find_nondominated_3d_impl_sorted(const double ** restrict rows, size_t size,
428431
if (dominated) { // pj is dominated by a point in the tree or by prev.
429432
if (find_one_dominated) {
430433
// In this context, it means "position of the first dominated solution found".
431-
new_size = j;
434+
new_size = pos_dom;
432435
goto early_end;
433436
}
434437
last_dom = pj;
435-
rows[j] = NULL;
438+
rows[pos_dom] = NULL;
436439
new_size--;
437440
} else {
438441
pk = pj;
442+
k = j;
439443
}
440444
j++;
441445
} while (j < size);

0 commit comments

Comments
 (0)