]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.db.impl/src/org/simantics/db/impl/query/ValueUpdateSet.java
Add possibility to bookkeep barrier tracing with env var
[simantics/platform.git] / bundles / org.simantics.db.impl / src / org / simantics / db / impl / query / ValueUpdateSet.java
1 package org.simantics.db.impl.query;
2
3 import gnu.trove.procedure.TIntProcedure;
4 import gnu.trove.set.hash.TIntHashSet;
5
6 final public class ValueUpdateSet {
7
8         private int first = 0;
9         public TIntHashSet rest = new TIntHashSet();
10         
11         public int size() {
12                 if(first != 0) return 1;
13                 else return rest.size();
14         }
15         
16         public int getFirst() {
17                 return first;
18         }
19         
20         public void add(int l) {
21                 if(first == 0) {
22                         if(rest.isEmpty()) {
23                                 first = l;
24                         } else {
25                                 rest.add(l);
26                         }
27                 } else {
28                         if(l == first) return;
29                         rest.add(first);
30                         rest.add(l);
31                         first = 0;
32                 }
33         }
34         
35         public void clear() {
36                 first = 0;
37                 if(!rest.isEmpty()) {
38                         rest = new TIntHashSet();
39                         //System.err.println("new rest!");
40                 }
41         }
42         
43         public void forEach(TIntProcedure proc) {
44                 if(first != 0) {
45                         proc.execute(first);
46                 } else {
47                         rest.forEach(proc);
48                 }
49         }
50         
51 }