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

39
LINES

< > BotCompany Repo | #1017600 // Computation Tree Include v2

JavaX fragment (include)

abstract sclass CTNode {
  new LinkedHashSet<CTNode> children;
  
  toString { ret joinNemptiesWithColonSpace(shortClassName(this), toString2()); }
  S toString2() { ret ""; } // override me
  
  bool add(CTNode n) { ret children.add(n); }
}

sclass ObjectNode<A> extends CTNode {
  A obj;
  
  *() {}
  *(A *obj) {}
  
  S toString2() { ret sfu(obj); }
  
  public bool equals(O o) { ret stdEq(this, o, 'obj); }
  public int hashCode() { ret stdHash(this, 'obj); }
}

sclass OpNode > CTNode {
  S op;
  bool haveResult;
  O result; // this is the result coming back up from the operation
  
  *() {}
  *(S *op) {}
  
  S toString2() { ret haveResult ? result + " <- " + op : op; }
  
  public bool equals(O o) { ret stdEq(this, o, 'op); }
  public int hashCode() { ret stdHash(this, 'op); }
  
  void setResult(O o) {
    result = o;
    haveResult = true;
  }
}

Author comment

Began life as a copy of #1017535

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1017600
Snippet name: Computation Tree Include v2
Eternal ID of this version: #1017600/4
Text MD5: 544e650b820088f6fbc46a2ba1f7bb32
Author: stefan
Category: javax / a.i.
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-07-29 17:28:46
Source code size: 901 bytes / 39 lines
Pitched / IR pitched: No / No
Views / Downloads: 351 / 522
Version history: 3 change(s)
Referenced in: [show references]