Libraryless. Click here for Pure Java version (9729L/53K).
1 | sclass Lowest<A> is IBest<A> {
|
2 | A best; |
3 | double score; |
4 | transient O onChange; |
5 | |
6 | synchronized bool isNewBest(double score) {
|
7 | ret best == null || score < this.score; |
8 | } |
9 | |
10 | synchronized double bestScore() {
|
11 | ret best == null ? Double.NaN : score; |
12 | } |
13 | |
14 | double score() { ret bestScore(); }
|
15 | |
16 | synchronized float floatScore() {
|
17 | ret best == null ? Float.NaN : (float) score; |
18 | } |
19 | |
20 | synchronized float floatScoreOr(float defaultValue) {
|
21 | ret best == null ? defaultValue : (float) score; |
22 | } |
23 | |
24 | public bool put(A a, double score) {
|
25 | bool change = false; |
26 | synchronized(this) {
|
27 | if (a != null && isNewBest(score)) {
|
28 | best = a; |
29 | this.score = score; |
30 | change = true; |
31 | } |
32 | } |
33 | if (change) |
34 | pcallF(onChange); |
35 | ret change; |
36 | } |
37 | |
38 | synchronized void clear() { best = null; score = 0; }
|
39 | |
40 | synchronized A get() { ret best; }
|
41 | synchronized bool has() { ret best != null; }
|
42 | synchronized Pair<A, Double> pair() { ret best == null ? null : Pair(best, bestScore()); }
|
43 | |
44 | toString {
|
45 | ret "Score " + formatDouble_significant2(score, 4) + ": " + best; |
46 | } |
47 | } |
Began life as a copy of #1006090
download show line numbers debug dex old transpilations
Travelled to 18 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, ppjhyzlbdabe, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
| Snippet ID: | #1006448 |
| Snippet name: | class Lowest - like Best, but collects item with lowest score |
| Eternal ID of this version: | #1006448/12 |
| Text MD5: | de0be6e56f8549f507a3782e57312c45 |
| Transpilation MD5: | 1af45cd24a20e0abac3edd7eacbb005d |
| Author: | stefan |
| Category: | javax / genetic optimization |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2022-11-21 11:29:55 |
| Source code size: | 1169 bytes / 47 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 1170 / 4982 |
| Version history: | 11 change(s) |
| Referenced in: | [show references] |