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

66
LINES

< > BotCompany Repo | #1035008 // PtSet - hash set of points (Pt) based on CompactLongSet [dev.]

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

Libraryless. Click here for Pure Java version (8492L/48K).

sclass PtSet extends java.util.AbstractSet<Pt> {
  final CompactLongSet set;
  
  *() { set = new CompactLongSet; }
  *(int size) { set = new CompactLongSet(size); }
  
  *(Iterable<Pt> l) {
    this();
    if (l != null) for (Pt p : l) add(p);
  }
  
  *(Cl<Pt> l) {
    this(l(l));
    if (l != null) for (Pt p : l) add(p);
  }
  
  public int size() { ret set.size(); }
  
  @Override
  public bool contains(O o) {
    ret contains(o/Pt);
  }
  
  public bool contains(Pt p) {
    ret set.contains(ptToLong(p));
  }
  
  public bool contains(int x, int y) {
    ret set.contains(ptToLong(x, y));
  }
  
  public bool add(Pt p) {
    ret set.add(ptToLong(p));
  }
  
  public bool add(int x, int y) {
    ret set.add(ptToLong(x, y));
  }
  
  public bool remove(Pt p) {
    ret set.remove(ptToLong(p));
  }
  
  public bool remove(int x, int y) {
    ret set.remove(ptToLong(x, y));
  }
  
  public void clear { set.clear(); }
  
  public Iterator<Pt> iterator() {
    RenamedLongIterator it = set.iterator();
    ret new ItIt<Pt> {
      public bool hasNext() {
        ret it.hasNext();
      }
      
      public Pt next() {
        ret ptFromLong(it.nextLong());
      }
      
      public void remove() {
        it.remove();
      }
    };
  }
}

Author comment

Began life as a copy of #1033756

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035008
Snippet name: PtSet - hash set of points (Pt) based on CompactLongSet [dev.]
Eternal ID of this version: #1035008/8
Text MD5: 8a82dff65fdaca45620539e139051300
Transpilation MD5: 624298d70400db2bacdceb12239d7177
Author: stefan
Category: javax / collections
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-05-13 15:02:47
Source code size: 1320 bytes / 66 lines
Pitched / IR pitched: No / No
Views / Downloads: 229 / 311
Version history: 7 change(s)
Referenced in: [show references]