aa
com.cliffc.aa.util.IBitSet Class Reference
Inheritance diagram for com.cliffc.aa.util.IBitSet:
[legend]
Collaboration diagram for com.cliffc.aa.util.IBitSet:
[legend]

Classes

class  Iter
 

Public Member Functions

int bitCount ()
 
IBitSet clear ()
 
boolean clr (int idx)
 
boolean disjoint (IBitSet bs)
 
IBitSet flip ()
 
boolean is_empty ()
 
Iterator< Integer > iterator ()
 
int max ()
 
IBitSet or (IBitSet bs)
 
boolean set (int idx)
 
boolean subsetsX (IBitSet bs)
 
void subtract (IBitSet bs)
 
String toString ()
 
SB toString (SB sb)
 
boolean tst (int idx)
 

Static Public Attributes

static final IBitSet EMPTY = new IBitSet()
 
static final IBitSet FULL = new IBitSet().flip()
 

Private Member Functions

boolean _clr (int idx)
 
boolean _set (int idx)
 
boolean _tst (int idx)
 
int wd (int x)
 
int xd (int x)
 

Static Private Member Functions

static int idx (int i)
 
static int mask (int i)
 

Private Attributes

final AryInt _bits = new AryInt()
 
boolean _sign
 

Detailed Description

Definition at line 10 of file IBitSet.java.

Member Function Documentation

◆ _clr()

boolean com.cliffc.aa.util.IBitSet._clr ( int  idx)
private

Definition at line 36 of file IBitSet.java.

36  {
37  int widx = idx (idx);
38  int mask = mask(idx);
39  int bits = _bits.atX(widx);
40  _bits.setX(widx, bits & ~mask);
41  while( _bits._len>0 && _bits.last()==0 ) _bits.pop(); // Shrink
42  return (bits&mask)!=0;
43  }

References com.cliffc.aa.util.IBitSet._bits, com.cliffc.aa.util.AryInt._len, com.cliffc.aa.util.AryInt.atX(), com.cliffc.aa.util.IBitSet.idx(), com.cliffc.aa.util.AryInt.last(), com.cliffc.aa.util.IBitSet.mask(), com.cliffc.aa.util.AryInt.pop(), and com.cliffc.aa.util.AryInt.setX().

Referenced by com.cliffc.aa.util.IBitSet.clr(), and com.cliffc.aa.util.IBitSet.set().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _set()

boolean com.cliffc.aa.util.IBitSet._set ( int  idx)
private

Definition at line 29 of file IBitSet.java.

29  {
30  int widx = idx (idx);
31  int mask = mask(idx);
32  int bits = _bits.atX(widx);
33  _bits.setX(widx, bits | mask);
34  return (bits&mask)!=0;
35  }

References com.cliffc.aa.util.IBitSet._bits, com.cliffc.aa.util.AryInt.atX(), com.cliffc.aa.util.IBitSet.idx(), com.cliffc.aa.util.IBitSet.mask(), and com.cliffc.aa.util.AryInt.setX().

Referenced by com.cliffc.aa.util.IBitSet.clr(), and com.cliffc.aa.util.IBitSet.set().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _tst()

boolean com.cliffc.aa.util.IBitSet._tst ( int  idx)
private

Definition at line 23 of file IBitSet.java.

23 { return (_bits.atX(idx(idx)) & mask(idx)) != 0; }

References com.cliffc.aa.util.IBitSet._bits, com.cliffc.aa.util.AryInt.atX(), com.cliffc.aa.util.IBitSet.idx(), and com.cliffc.aa.util.IBitSet.mask().

Referenced by com.cliffc.aa.util.IBitSet.tst().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bitCount()

int com.cliffc.aa.util.IBitSet.bitCount ( )

Definition at line 47 of file IBitSet.java.

47  {
48  assert !_sign; // Infinite if sign is set
49  int sum=0;
50  for( int i=0; i<_bits._len; i++ )
51  sum += Integer.bitCount(_bits._es[i]);
52  return sum;
53  }

References com.cliffc.aa.util.IBitSet._bits, com.cliffc.aa.util.AryInt._es, com.cliffc.aa.util.AryInt._len, and com.cliffc.aa.util.IBitSet._sign.

◆ clear()

IBitSet com.cliffc.aa.util.IBitSet.clear ( )

Definition at line 66 of file IBitSet.java.

66  {
67  _sign=false;
68  _bits.clear();
69  return this;
70  }

References com.cliffc.aa.util.IBitSet._bits, com.cliffc.aa.util.IBitSet._sign, and com.cliffc.aa.util.AryInt.clear().

Here is the call graph for this function:

◆ clr()

boolean com.cliffc.aa.util.IBitSet.clr ( int  idx)

Definition at line 27 of file IBitSet.java.

27 { return _sign ? !_set(idx) : _clr(idx); }

References com.cliffc.aa.util.IBitSet._clr(), com.cliffc.aa.util.IBitSet._set(), com.cliffc.aa.util.IBitSet._sign, and com.cliffc.aa.util.IBitSet.idx().

Here is the call graph for this function:

◆ disjoint()

boolean com.cliffc.aa.util.IBitSet.disjoint ( IBitSet  bs)

Definition at line 88 of file IBitSet.java.

88  {
89  if( is_empty() ) return true; // Empty set must be disjoint
90  if( bs.is_empty() ) return true; // Empty set must be disjoint
91  if( _sign && bs._sign ) return false; // Both extensions are set
92  IBitSet min = this;
93  if( _bits._len > bs._bits._len ) { min=bs; bs=this; } // max in bs
94  if( min._sign && min._bits._len < bs._bits._len ) return false; // Extension in min overlaps last bits in max
95  for( int i=0; i<min._bits._len; i++ )
96  if( (min.wd(i)&bs.wd(i))!= 0 )
97  return false;
98  return true;
99  }

References com.cliffc.aa.util.IBitSet._bits, com.cliffc.aa.util.AryInt._len, com.cliffc.aa.util.IBitSet._sign, com.cliffc.aa.util.IBitSet.is_empty(), and com.cliffc.aa.util.IBitSet.wd().

Here is the call graph for this function:

◆ flip()

IBitSet com.cliffc.aa.util.IBitSet.flip ( )

Definition at line 45 of file IBitSet.java.

45 { _sign=!_sign; return this; }

References com.cliffc.aa.util.IBitSet._sign.

◆ idx()

static int com.cliffc.aa.util.IBitSet.idx ( int  i)
staticprivate

Definition at line 18 of file IBitSet.java.

18 { return i>>5; }

Referenced by com.cliffc.aa.util.IBitSet._clr(), com.cliffc.aa.util.IBitSet._set(), com.cliffc.aa.util.IBitSet._tst(), com.cliffc.aa.util.IBitSet.clr(), com.cliffc.aa.util.IBitSet.Iter.hasNext(), com.cliffc.aa.util.IBitSet.Iter.next(), com.cliffc.aa.util.IBitSet.set(), and com.cliffc.aa.util.IBitSet.tst().

Here is the caller graph for this function:

◆ is_empty()

boolean com.cliffc.aa.util.IBitSet.is_empty ( )

Definition at line 85 of file IBitSet.java.

85 { return _bits._len==0 && !_sign; }

References com.cliffc.aa.util.IBitSet._bits, com.cliffc.aa.util.AryInt._len, and com.cliffc.aa.util.IBitSet._sign.

Referenced by com.cliffc.aa.util.IBitSet.disjoint(), and com.cliffc.aa.util.IBitSet.subsetsX().

Here is the caller graph for this function:

◆ iterator()

Iterator<Integer> com.cliffc.aa.util.IBitSet.iterator ( )
Returns
an iterator

Definition at line 134 of file IBitSet.java.

134 { return new Iter(); }

◆ mask()

static int com.cliffc.aa.util.IBitSet.mask ( int  i)
staticprivate

Definition at line 19 of file IBitSet.java.

19 { return 1<<(i&31); }

Referenced by com.cliffc.aa.util.IBitSet._clr(), com.cliffc.aa.util.IBitSet._set(), com.cliffc.aa.util.IBitSet._tst(), and com.cliffc.aa.util.IBitSet.Iter.hasNext().

Here is the caller graph for this function:

◆ max()

int com.cliffc.aa.util.IBitSet.max ( )

Definition at line 54 of file IBitSet.java.

54  {
55  assert !_sign; // Infinite if sign is set
56  if( _bits._len==0 ) return 0;
57  return (31 - Integer.numberOfLeadingZeros(_bits.last()))+((_bits._len-1)<<5);
58  }

References com.cliffc.aa.util.IBitSet._bits, com.cliffc.aa.util.AryInt._len, com.cliffc.aa.util.IBitSet._sign, and com.cliffc.aa.util.AryInt.last().

Referenced by com.cliffc.aa.util.IBitSet.subsetsX().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ or()

IBitSet com.cliffc.aa.util.IBitSet.or ( IBitSet  bs)

Definition at line 73 of file IBitSet.java.

73  {
74  _sign |= bs._sign;
75  for( int i=0; i<bs._bits._len; i++ )
76  _bits.setX(i,_bits.atX(i)|bs.wd(i));
77  return this;
78  }

References com.cliffc.aa.util.IBitSet._bits, com.cliffc.aa.util.AryInt._len, com.cliffc.aa.util.IBitSet._sign, com.cliffc.aa.util.AryInt.atX(), com.cliffc.aa.util.AryInt.setX(), and com.cliffc.aa.util.IBitSet.wd().

Here is the call graph for this function:

◆ set()

boolean com.cliffc.aa.util.IBitSet.set ( int  idx)

Definition at line 26 of file IBitSet.java.

26 { return _sign ? !_clr(idx) : _set(idx); }

References com.cliffc.aa.util.IBitSet._clr(), com.cliffc.aa.util.IBitSet._set(), com.cliffc.aa.util.IBitSet._sign, and com.cliffc.aa.util.IBitSet.idx().

Referenced by com.cliffc.aa.type.Bits< BitsRPC >.bitset(), and com.cliffc.aa.HM.HM4.T2.live().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ subsetsX()

boolean com.cliffc.aa.util.IBitSet.subsetsX ( IBitSet  bs)

Definition at line 103 of file IBitSet.java.

103  {
104  assert !bs.is_empty(); // Undefined
105  int max=Math.max(_bits._len,bs._bits._len);
106  for( int i=0; i<max; i++ )
107  if( (xd(i)|bs.xd(i)) != bs.xd(i) ) // All bits in common
108  return false;
109  return true;
110  }

References com.cliffc.aa.util.IBitSet._bits, com.cliffc.aa.util.AryInt._len, com.cliffc.aa.util.IBitSet.is_empty(), com.cliffc.aa.util.IBitSet.max(), and com.cliffc.aa.util.IBitSet.xd().

Here is the call graph for this function:

◆ subtract()

void com.cliffc.aa.util.IBitSet.subtract ( IBitSet  bs)

Definition at line 80 of file IBitSet.java.

80  {
81  for( int i=0; i<bs._bits._len; i++ )
82  _bits.setX(i,_bits.atX(i)&~bs.wd(i));
83  }

References com.cliffc.aa.util.IBitSet._bits, com.cliffc.aa.util.AryInt._len, com.cliffc.aa.util.AryInt.atX(), com.cliffc.aa.util.AryInt.setX(), and com.cliffc.aa.util.IBitSet.wd().

Here is the call graph for this function:

◆ toString() [1/2]

String com.cliffc.aa.util.IBitSet.toString ( )

Definition at line 112 of file IBitSet.java.

112 { return toString(new SB()).toString(); }

References com.cliffc.aa.util.IBitSet.toString().

Referenced by com.cliffc.aa.util.IBitSet.toString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ toString() [2/2]

SB com.cliffc.aa.util.IBitSet.toString ( SB  sb)

Definition at line 113 of file IBitSet.java.

113  {
114  if( _bits._len==0 ) return sb.p(_sign?"[...]":"[]");
115  int x = -1; // No range-in-process
116  sb.p('[');
117  for( int i=0; i<_bits._len*32+1; i++ ) {
118  if( tst(i) ) {
119  if( x==-1 ) x=i; // Start a range
120  } else {
121  if( x!=-1 ) { // End a range
122  if( x+1==i ) sb.p(x).p(',');
123  else if( x+2==i ) sb.p(x).p(',').p(i-1).p(',');
124  else sb.p(x).p("...").p(i-1).p(',');
125  x = -1;
126  }
127  }
128  }
129  if( x != -1 ) sb.p(x).p("...,"); // Close open range
130  return sb.unchar().p(']');
131  }

References com.cliffc.aa.util.IBitSet._bits, com.cliffc.aa.util.AryInt._len, com.cliffc.aa.util.IBitSet._sign, com.cliffc.aa.util.SB.p(), com.cliffc.aa.util.IBitSet.tst(), and com.cliffc.aa.util.SB.unchar().

Here is the call graph for this function:

◆ tst()

boolean com.cliffc.aa.util.IBitSet.tst ( int  idx)

Definition at line 22 of file IBitSet.java.

22 { return _sign != _tst(idx); }

References com.cliffc.aa.util.IBitSet._sign, com.cliffc.aa.util.IBitSet._tst(), and com.cliffc.aa.util.IBitSet.idx().

Referenced by com.cliffc.aa.util.IBitSet.toString().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ wd()

int com.cliffc.aa.util.IBitSet.wd ( int  x)
private

Definition at line 60 of file IBitSet.java.

60 { return _bits._es[x]; }

References com.cliffc.aa.util.IBitSet._bits, and com.cliffc.aa.util.AryInt._es.

Referenced by com.cliffc.aa.util.IBitSet.disjoint(), com.cliffc.aa.util.IBitSet.or(), and com.cliffc.aa.util.IBitSet.subtract().

Here is the caller graph for this function:

◆ xd()

int com.cliffc.aa.util.IBitSet.xd ( int  x)
private

Definition at line 61 of file IBitSet.java.

61  {
62  int b = _bits.atX(x); // zero extend if off end
63  return _sign ? ~b : b;// adjust for sign
64  }

References com.cliffc.aa.util.IBitSet._bits, com.cliffc.aa.util.IBitSet._sign, and com.cliffc.aa.util.AryInt.atX().

Referenced by com.cliffc.aa.util.IBitSet.subsetsX().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ _bits

◆ _sign

◆ EMPTY

final IBitSet com.cliffc.aa.util.IBitSet.EMPTY = new IBitSet()
static

Definition at line 15 of file IBitSet.java.

◆ FULL

final IBitSet com.cliffc.aa.util.IBitSet.FULL = new IBitSet().flip()
static

Definition at line 16 of file IBitSet.java.


The documentation for this class was generated from the following file:
com.cliffc.aa.util.AryInt.atX
int atX(int i)
Definition: AryInt.java:27
com.cliffc.aa.util.IBitSet.max
int max()
Definition: IBitSet.java:54
com.cliffc.aa.util.IBitSet._set
boolean _set(int idx)
Definition: IBitSet.java:29
com.cliffc.aa.util.IBitSet.is_empty
boolean is_empty()
Definition: IBitSet.java:85
com.cliffc.aa.util.IBitSet.mask
static int mask(int i)
Definition: IBitSet.java:19
com.cliffc.aa.util.IBitSet._clr
boolean _clr(int idx)
Definition: IBitSet.java:36
com.cliffc.aa.util.IBitSet.xd
int xd(int x)
Definition: IBitSet.java:61
com.cliffc.aa.util.IBitSet.tst
boolean tst(int idx)
Definition: IBitSet.java:22
com.cliffc.aa.util.AryInt.pop
int pop()
Definition: AryInt.java:37
com.cliffc.aa.util.IBitSet.idx
static int idx(int i)
Definition: IBitSet.java:18
com.cliffc.aa.util.AryInt._es
int[] _es
Definition: AryInt.java:9
com.cliffc.aa.util.IBitSet._sign
boolean _sign
Definition: IBitSet.java:11
com.cliffc.aa.util.IBitSet._tst
boolean _tst(int idx)
Definition: IBitSet.java:23
com.cliffc.aa.util.IBitSet.toString
String toString()
Definition: IBitSet.java:112
com.cliffc.aa.util.AryInt.last
int last()
Definition: AryInt.java:31
com.cliffc.aa.util.IBitSet._bits
final AryInt _bits
Definition: IBitSet.java:12
com.cliffc.aa.util.AryInt.clear
void clear()
Remove all elements.
Definition: AryInt.java:84
com.cliffc.aa.util.AryInt.setX
int setX(int i, int e)
Definition: AryInt.java:87
com.cliffc.aa.util.AryInt._len
int _len
Definition: AryInt.java:10