Libraryless. Click here for Pure Java version (3469L/19K).
1 | sclass WithProbability<A> extends Var<A> implements Comparable<WithProbability<A>> {
|
2 | double probability; // assumed between 0 and 1 |
3 | |
4 | *() {}
|
5 | *(A a) { this(1, a); }
|
6 | *(double *probability, A a) { super(a); }
|
7 | |
8 | toString {
|
9 | ret "p=" + renderedProbability() + ": " + str(get()); |
10 | } |
11 | |
12 | S renderedProbability() {
|
13 | ret formatDouble_noLeadingZero(probability, 2); |
14 | } |
15 | |
16 | double probability() { ret probability; }
|
17 | |
18 | public int hashCode() {
|
19 | ret boostHashCombine(main hashCode(probability), main hashCode(get())); |
20 | } |
21 | |
22 | public bool equals(O o) {
|
23 | if (o cast WithProbability) {
|
24 | ret probability == o.probability && eq(get(), o!); |
25 | } |
26 | false; |
27 | } |
28 | |
29 | // Higher probability comes first! |
30 | public int compareTo(WithProbability<A> wp) {
|
31 | ret wp == null ? 1 |
32 | : cmp(wp.probability, probability); |
33 | } |
34 | } |
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: | #1028471 |
| Snippet name: | WithProbability - probability (0 to 1) is first argument in constructor |
| Eternal ID of this version: | #1028471/9 |
| Text MD5: | bc649173a90af0ac81b0431b44d891d5 |
| Transpilation MD5: | 3d86c307a787071852c5ace5abb7fda7 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2021-08-20 06:33:50 |
| Source code size: | 870 bytes / 34 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 591 / 990 |
| Version history: | 8 change(s) |
| Referenced in: | [show references] |