Libraryless. Click here for Pure Java version (2557L/16K).
sclass DynamicTopTen<A> { new LPair<A, Double> list; int n = 10; void add(A a, double score) { put(a, score); } void put(A a, double score) { int i = l(list); while (i > 0 && list.get(i-1).b < score) --i; if (i >= n) ret; if (l(list) == n) removeLast(list); list.add(i, pair(a, score)); } L<A> get() { ret pairsA(list); } LPair<A, Double> withScores() { ret list; } }
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1027477 |
Snippet name: | DynamicTopTen - not-so-optimized version using an ArrayList. Could use TreeSetWithDuplicates |
Eternal ID of this version: | #1027477/6 |
Text MD5: | 1c1ea8338bc25a0aa114ffc83c19d089 |
Transpilation MD5: | 1114cb31d4e1b8ca46b2966706a4e0d3 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-04-18 12:27:03 |
Source code size: | 453 bytes / 23 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 241 / 584 |
Version history: | 5 change(s) |
Referenced in: | #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674) |