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

23
LINES

< > BotCompany Repo | #1008857 // LazyValueTreeMap

JavaX fragment (include)

sclass LazyValueTreeMap<A, B> extends TreeMap<A, B> {
  static O placeholder = new O; // fool type system
  O valueMaker;
  
  *(Collection<A> keys, O *valueMaker) {
    for (A key : unnull(keys)) put(key, (B) placeholder);
  }
  
  public B get(O key) {
    B value = super.get(key);
    if (value == placeholder)
      put((A) key, value = (B) callF(valueMaker, key));
    ret value;
  }
  
  int numPlaceholders() {
    ret countOccurrences_id(values(), placeholder);
  }
  
  // revert to identity hashcode
  public bool equals(O o) { ret this == o; }
  public int hashCode() { ret systemHashCode(this); }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1008857
Snippet name: LazyValueTreeMap
Eternal ID of this version: #1008857/9
Text MD5: ccd726f33cf327886fce159b106a2cff
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2017-06-14 14:01:58
Source code size: 633 bytes / 23 lines
Pitched / IR pitched: No / No
Views / Downloads: 471 / 1477
Version history: 8 change(s)
Referenced in: [show references]