Skip to content

Commit

Permalink
ADD getBestFromResults
Browse files Browse the repository at this point in the history
  • Loading branch information
deepnight committed Feb 12, 2025
1 parent 54334cb commit 1a4a3d0
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/dn/DecisionHelper.hx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ class DecisionHelper<T> {
}

inline function isDiscarded(idx:Int) {
return scores.exists(idx) && scores.get(idx)==DISCARDED;
return scores.exists(idx) && isDiscardScore( scores.get(idx) );
}

static inline function isDiscardScore(s:Float) : Bool {
return s==DISCARDED;
}


Expand Down Expand Up @@ -168,6 +172,19 @@ class DecisionHelper<T> {
return out;
}

/* Return the best value from a set of DecisionHelperResult<T> */
public static function getBestFromResults<T>(results : Array<DecisionHelperResult<T>>) : Null<T> {
var best : Null< DecisionHelperResult<T> > = null;
var idx = 0;
for(r in results) {
if( !isDiscardScore(r.score) && ( best==null || r.score>best.score ) )
best = r;
idx++;
}
return best.value;
}


/** Return the non-discarded value with the highest score. **/
public function getBest() : Null<T> {
var bestIdx = -1;
Expand Down

0 comments on commit 1a4a3d0

Please sign in to comment.