Libraryless. Click here for Pure Java version (4279L/24K).
1 | // always keeps a dynamically updated list of the n most probable |
2 | // results |
3 | |
4 | // not synchronized |
5 | sclass SetOfMostProbable<A> extends TreeSetWithDuplicates<WithProbability<A>> { |
6 | int maxSize = 10; |
7 | |
8 | *() {} |
9 | *(int *maxSize) {} |
10 | |
11 | public bool add(WithProbability<A> a) { |
12 | if (a == null) false; |
13 | super.add(a); |
14 | truncate(); |
15 | true; |
16 | } |
17 | |
18 | void setMaxSize(int maxSize) { |
19 | this.maxSize = maxSize; |
20 | truncate(); |
21 | } |
22 | |
23 | void truncate { |
24 | truncateTreeSetWithDuplicates(this, maxSize); |
25 | } |
26 | } |
Began life as a copy of #1032061
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx
No comments. add comment
Snippet ID: | #1032063 |
Snippet name: | SetOfMostProbable |
Eternal ID of this version: | #1032063/7 |
Text MD5: | b5e0fa14e0e8c53460b73529c1b6665a |
Transpilation MD5: | eff28acc8e5b802198d2594530eb9a7d |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-08-11 10:15:58 |
Source code size: | 533 bytes / 26 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 169 / 314 |
Version history: | 6 change(s) |
Referenced in: | [show references] |