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

43
LINES

< > BotCompany Repo | #1035855 // G22HashedMasks backup

JavaX fragment (include)

// A is the user object associated with each mask (aka a "label")
sclass G22HashedMasks<A> {
  record noeq Mask(Image2B image, A label) is IG22Mask<A> {
    int hash, count;
    
    public int hashCode() {
      if (hash == 0)
        hash = (int) hashImage2B(image);
      ret hash;
    }
    
    public Image2B image() { ret image; }
    public A label() { ret label; }
  }

  new Map<Int, Mask> masks;

  void addRegion(IImageRegion region, A label) {
    var mask = new Mask(regionToMaskImage(region), label);
    var existingMask = masks.get(mask.hashCode());
    if (existingMask != null) {
      labels.remove(existingMask.label);
      existingMask.label = combineLabels(existingMask.label, mask.label);
      mask = existingMask;
    } else
      masks.put(mask.hashCode(), mask);
    ghost_cache = null;
    certainty_cache = null;
    labels.add(mask.label);
    mask.count++;
  }
  
  swappable A combineLabels(A a, A b) {
    if (a == null) ret b;
    if (b == null) ret a;
    if (eq(a, b)) ret a;
    fail("Label conflict: " + a + " / " + b);
  }
  
  L<Mask> masks() { ret valuesList(masks); }
  
  !include early #1035854 // Masks holder Include
}

Author comment

Began life as a copy of #1035850

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): mqqgnosmbjvj, wnsclhtenguj

No comments. add comment

-
Snippet ID: #1035855
Snippet name: G22HashedMasks backup
Eternal ID of this version: #1035855/1
Text MD5: 9e014ef752d344d2ed482eea8dcd0dff
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-08-03 02:19:03
Source code size: 1208 bytes / 43 lines
Pitched / IR pitched: No / No
Views / Downloads: 117 / 116
Referenced in: