Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

26
LINES

< > BotCompany Repo | #1032063 // SetOfMostProbable

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4279L/24K).

// always keeps a dynamically updated list of the n most probable
// results

// not synchronized
sclass SetOfMostProbable<A> extends TreeSetWithDuplicates<WithProbability<A>> {
  int maxSize = 10;

  *() {}
  *(int *maxSize) {}
  
  public bool add(WithProbability<A> a) {
    if (a == null) false;
    super.add(a);
    truncate();
    true;
  }
  
  void setMaxSize(int maxSize) {
    this.maxSize = maxSize;
    truncate();
  }
  
  void truncate {
    truncateTreeSetWithDuplicates(this, maxSize);
  }
}

Author comment

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: 167 / 310
Version history: 6 change(s)
Referenced in: [show references]