@@ -344,7 +344,7 @@ find_nondominated_set_2d_(const double * restrict points, size_t size,
344344 When find_one_dominated, return as soon as it finds one dominated point.
345345*/
346346static __force_inline__ size_t
347- find_nondominated_3d_impl_sorted (const double * * restrict rows , size_t size ,
347+ find_nondominated_3d_impl_sorted (const double * * rows , size_t size ,
348348 const bool keep_weakly ,
349349 const bool find_one_dominated )
350350{
@@ -367,7 +367,6 @@ find_nondominated_3d_impl_sorted(const double ** restrict rows, size_t size,
367367 const double * restrict pk = rows [0 ];
368368 do {
369369 bool dominated ;
370- size_t pos_dom = j ;
371370 const double * restrict pj = rows [j ];
372371 DEBUG2 (printf_point ("pj = [ " , pj , 3 , " ], " ));
373372 if (pk [0 ] > pj [0 ] || pk [1 ] > pj [1 ]) {
@@ -416,10 +415,18 @@ find_nondominated_3d_impl_sorted(const double ** restrict rows, size_t size,
416415 // previous one.
417416 const bool k_eq_j = (pk [0 ] == pj [0 ]) & (pk [1 ] == pj [1 ]) & (pk [2 ] == pj [2 ]);
418417 if (!keep_weakly ) { // We don't keep duplicates;
419- dominated = true;
420418 if (unlikely (k_eq_j ) && pj < pk ) { // Only the first duplicated point is kept.
421- pos_dom = k ;
422- pj = pk ;
419+ if (find_one_dominated ) {
420+ // In this context, it means "position of the first dominated solution found".
421+ new_size = k ;
422+ goto early_end ;
423+ }
424+ last_dom = pk ;
425+ rows [k ] = NULL ;
426+ new_size -- ;
427+ dominated = false; // Do not delete pj.
428+ } else {
429+ dominated = true;
423430 }
424431 } else { // or it is not a duplicate, so it is non-weakly dominated;
425432 dominated = likely (!k_eq_j )
@@ -431,11 +438,11 @@ find_nondominated_3d_impl_sorted(const double ** restrict rows, size_t size,
431438 if (dominated ) { // pj is dominated by a point in the tree or by prev.
432439 if (find_one_dominated ) {
433440 // In this context, it means "position of the first dominated solution found".
434- new_size = pos_dom ;
441+ new_size = j ;
435442 goto early_end ;
436443 }
437444 last_dom = pj ;
438- rows [pos_dom ] = NULL ;
445+ rows [j ] = NULL ;
439446 new_size -- ;
440447 } else {
441448 pk = pj ;
0 commit comments