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

43
LINES

< > BotCompany Repo | #1035855 // G22HashedMasks backup

JavaX fragment (include)

1  
// A is the user object associated with each mask (aka a "label")
2  
sclass G22HashedMasks<A> {
3  
  record noeq Mask(Image2B image, A label) is IG22Mask<A> {
4  
    int hash, count;
5  
    
6  
    public int hashCode() {
7  
      if (hash == 0)
8  
        hash = (int) hashImage2B(image);
9  
      ret hash;
10  
    }
11  
    
12  
    public Image2B image() { ret image; }
13  
    public A label() { ret label; }
14  
  }
15  
16  
  new Map<Int, Mask> masks;
17  
18  
  void addRegion(IImageRegion region, A label) {
19  
    var mask = new Mask(regionToMaskImage(region), label);
20  
    var existingMask = masks.get(mask.hashCode());
21  
    if (existingMask != null) {
22  
      labels.remove(existingMask.label);
23  
      existingMask.label = combineLabels(existingMask.label, mask.label);
24  
      mask = existingMask;
25  
    } else
26  
      masks.put(mask.hashCode(), mask);
27  
    ghost_cache = null;
28  
    certainty_cache = null;
29  
    labels.add(mask.label);
30  
    mask.count++;
31  
  }
32  
  
33  
  swappable A combineLabels(A a, A b) {
34  
    if (a == null) ret b;
35  
    if (b == null) ret a;
36  
    if (eq(a, b)) ret a;
37  
    fail("Label conflict: " + a + " / " + b);
38  
  }
39  
  
40  
  L<Mask> masks() { ret valuesList(masks); }
41  
  
42  
  !include early #1035854 // Masks holder Include
43  
}

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: 56 / 59
Referenced in: [show references]