Libraryless. Click here for Pure Java version (5300L/30K).
1 | // always keeps a dynamically updated list of the n most probable |
2 | // results |
3 | |
4 | // for maxResults default, see SetOfMostProbable |
5 | |
6 | // not synchronized |
7 | srecord noeq PSCollectMostProbable<A>( |
8 | IVF1<IVF1<WithProbability<A>>> action) implements IF0<Set<WithProbability<A>>>, Steppable {
|
9 | |
10 | new ProbabilisticScheduler ps; |
11 | new SetOfMostProbable<A> results; |
12 | bool verbose; |
13 | |
14 | *() {}
|
15 | |
16 | *(int maxResults) {
|
17 | setMaxResults(maxResults); |
18 | } |
19 | |
20 | *(int maxResults, |
21 | ProbabilisticScheduler *ps, |
22 | IVF1<IVF1<WithProbability<A>>> *action) {
|
23 | setMaxResults(maxResults); |
24 | } |
25 | |
26 | *(int maxResults, IVF2<IProbabilisticScheduler, IVF1<WithProbability<A>>> action) {
|
27 | setMaxResults(maxResults); |
28 | this.action = out -> action.get(ps, out); |
29 | } |
30 | |
31 | void add(WithProbability<A> result) {
|
32 | results.add(result); |
33 | } |
34 | |
35 | selfType run() {
|
36 | action?.get(result -> add(result)); |
37 | this; |
38 | } |
39 | |
40 | void setMaxResults(int maxResults) {
|
41 | results.setMaxSize(maxResults); |
42 | } |
43 | |
44 | selfType verbose(bool verbose) { this.verbose = verbose; this; }
|
45 | |
46 | // results sorted by probability. instant |
47 | public Set<WithProbability<A>> results aka get() {
|
48 | ret results; |
49 | } |
50 | |
51 | public bool step() { ret ps.step(); }
|
52 | } |
Began life as a copy of #1032029
download show line numbers debug dex old transpilations
Travelled to 3 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx
No comments. add comment
| Snippet ID: | #1032061 |
| Snippet name: | PSCollectMostProbable |
| Eternal ID of this version: | #1032061/23 |
| Text MD5: | 2bc95f75130f9fdf6d49338e52bc29f2 |
| Transpilation MD5: | b59f2b95a74107ed518c8f60491987d7 |
| 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:19:30 |
| Source code size: | 1271 bytes / 52 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 415 / 654 |
| Version history: | 22 change(s) |
| Referenced in: | [show references] |