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

Public Member Functions

 AryInt ()
 
 AryInt (int[] es)
 
 AryInt (int[] es, int len)
 
AryInt addAll (Collection<? extends Integer > c)
 
AryInt addAll (int[] es)
 
int[] asAry ()
 
int at (int i)
 
int atX (int i)
 
int binary_search (int e)
 
void clear ()
 Remove all elements. More...
 
int del (int i)
 Fast, constant-time, element removal. More...
 
boolean equals (Object o)
 
int find (int e)
 Find the first matching element using ==, or -1 if none. More...
 
int hashCode ()
 
void insert (int i, int e)
 Slow, linear-time, element insert. More...
 
boolean isEmpty ()
 
int last ()
 
int len ()
 
AryInt map_update (IntUnaryOperator f)
 
int pop ()
 
AryInt push (int e)
 Add element in amortized constant time. More...
 
int remove (int i)
 Slow, linear-time, element removal. More...
 
int set (int i, int e)
 
AryInt set_as (int e)
 
AryInt set_len (int len)
 
int setX (int i, int e)
 
void sort_update ()
 Sorts in-place. More...
 
String toString ()
 

Public Attributes

int[] _es
 
int _len
 

Private Member Functions

void range_check (int i)
 

Detailed Description

Definition at line 8 of file AryInt.java.

Constructor & Destructor Documentation

◆ AryInt() [1/3]

com.cliffc.aa.util.AryInt.AryInt ( int[]  es)

Definition at line 11 of file AryInt.java.

11 { this(es,es.length); }

◆ AryInt() [2/3]

com.cliffc.aa.util.AryInt.AryInt ( int[]  es,
int  len 
)

Definition at line 12 of file AryInt.java.

12 { _es=es; _len=len; }

References com.cliffc.aa.util.AryInt._es, com.cliffc.aa.util.AryInt._len, and com.cliffc.aa.util.AryInt.len().

Here is the call graph for this function:

◆ AryInt() [3/3]

com.cliffc.aa.util.AryInt.AryInt ( )

Definition at line 13 of file AryInt.java.

13 { this(new int[1],0); }

Referenced by com.cliffc.aa.util.AryInt.equals().

Here is the caller graph for this function:

Member Function Documentation

◆ addAll() [1/2]

AryInt com.cliffc.aa.util.AryInt.addAll ( Collection<? extends Integer >  c)
Parameters
cCollection to be added

Definition at line 109 of file AryInt.java.

109 { for( int e : c ) push(e); return this; }

References com.cliffc.aa.util.AryInt.push().

Here is the call graph for this function:

◆ addAll() [2/2]

AryInt com.cliffc.aa.util.AryInt.addAll ( int[]  es)
Parameters
esArray to be added

Definition at line 112 of file AryInt.java.

112  {
113  if( es.length==0 ) return this;
114  while( _len+es.length > _es.length ) _es = Arrays.copyOf(_es,_es.length<<1);
115  System.arraycopy(es,0,_es,_len,es.length);
116  _len += es.length;
117  return this;
118  }

References com.cliffc.aa.util.AryInt._es, and com.cliffc.aa.util.AryInt._len.

◆ asAry()

int [] com.cliffc.aa.util.AryInt.asAry ( )
Returns
compact array version, using the internal base array where possible.

Definition at line 123 of file AryInt.java.

123 { return _len==_es.length ? _es : Arrays.copyOf(_es,_len); }

References com.cliffc.aa.util.AryInt._es, and com.cliffc.aa.util.AryInt._len.

◆ at()

int com.cliffc.aa.util.AryInt.at ( int  i)
Parameters
ielement index
Returns
element being returned; throws if OOB

Definition at line 21 of file AryInt.java.

21  {
22  range_check(i);
23  return _es[i];
24  }

References com.cliffc.aa.util.AryInt._es, and com.cliffc.aa.util.AryInt.range_check().

Referenced by com.cliffc.aa.Parse.errLocMsg().

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

◆ atX()

int com.cliffc.aa.util.AryInt.atX ( int  i)
Parameters
ielement index
Returns
element being returned, or 0 if OOB

Definition at line 27 of file AryInt.java.

27  {
28  return i < _len ? _es[i] : 0;
29  }

References com.cliffc.aa.util.AryInt._es, and com.cliffc.aa.util.AryInt._len.

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.or(), com.cliffc.aa.util.IBitSet.subtract(), and com.cliffc.aa.util.IBitSet.xd().

Here is the caller graph for this function:

◆ binary_search()

int com.cliffc.aa.util.AryInt.binary_search ( int  e)

Definition at line 150 of file AryInt.java.

150  {
151  int lo=0, hi=_len-1;
152  while( lo <= hi ) {
153  int mid = (hi + lo) >>> 1; // midpoint, rounded down
154  int mval = _es[mid];
155  if( e==mval ) {
156  // If dups, get to the first.
157  while( mid>0 && e==_es[mid-1] ) mid--;
158  return mid;
159  }
160  if( e >mval ) lo = mid+1;
161  else hi = mid-1;
162  }
163  return lo;
164  }

References com.cliffc.aa.util.AryInt._es, and com.cliffc.aa.util.AryInt._len.

Referenced by com.cliffc.aa.Parse.apply(), and com.cliffc.aa.Parse.errLocMsg().

Here is the caller graph for this function:

◆ clear()

void com.cliffc.aa.util.AryInt.clear ( )

Remove all elements.

Definition at line 84 of file AryInt.java.

84 { Arrays.fill(_es,0,_len,0); _len=0; }

References com.cliffc.aa.util.AryInt._es, and com.cliffc.aa.util.AryInt._len.

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

Here is the caller graph for this function:

◆ del()

int com.cliffc.aa.util.AryInt.del ( int  i)

Fast, constant-time, element removal.

Does not preserve order

Parameters
ielement to be removed
Returns
element removed

Definition at line 66 of file AryInt.java.

66  {
67  range_check(i);
68  int tmp = _es[i];
69  _es[i]=_es[--_len];
70  return tmp;
71  }

References com.cliffc.aa.util.AryInt._es, com.cliffc.aa.util.AryInt._len, and com.cliffc.aa.util.AryInt.range_check().

Here is the call graph for this function:

◆ equals()

boolean com.cliffc.aa.util.AryInt.equals ( Object  o)

Definition at line 169 of file AryInt.java.

169  {
170  if( this==o ) return true;
171  if( !(o instanceof AryInt) ) return false;
172  AryInt ary = (AryInt)o;
173  if( _len != ary._len ) return false;
174  if( _es == ary._es ) return true;
175  for( int i=0; i<_len; i++ )
176  if( _es[i] != ary._es[i] )
177  return false;
178  return true;
179  }

References com.cliffc.aa.util.AryInt._es, com.cliffc.aa.util.AryInt._len, and com.cliffc.aa.util.AryInt.AryInt().

Here is the call graph for this function:

◆ find()

int com.cliffc.aa.util.AryInt.find ( int  e)

Find the first matching element using ==, or -1 if none.

Note that most del calls shuffle the list, so the first element might be random.

Parameters
eintlement to find
Returns
index of first matching element, or -1 if none

Definition at line 131 of file AryInt.java.

131  {
132  for( int i=0; i<_len; i++ ) if( _es[i]==e ) return i;
133  return -1;
134  }

References com.cliffc.aa.util.AryInt._es, and com.cliffc.aa.util.AryInt._len.

◆ hashCode()

int com.cliffc.aa.util.AryInt.hashCode ( )

Definition at line 180 of file AryInt.java.

180  {
181  int sum=_len;
182  for( int i=0; i<_len; i++ )
183  sum += _es[i];
184  return sum;
185  }

References com.cliffc.aa.util.AryInt._es, and com.cliffc.aa.util.AryInt._len.

◆ insert()

void com.cliffc.aa.util.AryInt.insert ( int  i,
int  e 
)

Slow, linear-time, element insert.

Preserves order.

Parameters
iindex to insert at, between 0 and _len inclusive.
eintlement to insert

Definition at line 55 of file AryInt.java.

55  {
56  if( i < 0 || i>_len )
57  throw new ArrayIndexOutOfBoundsException(""+i+" >= "+_len);
58  if( _len >= _es.length ) _es = Arrays.copyOf(_es,Math.max(1,_es.length<<1));
59  System.arraycopy(_es,i,_es,i+1,(_len++)-i);
60  _es[i] = e;
61  }

References com.cliffc.aa.util.AryInt._es, and com.cliffc.aa.util.AryInt._len.

◆ isEmpty()

boolean com.cliffc.aa.util.AryInt.isEmpty ( )
Returns
list is empty

Definition at line 16 of file AryInt.java.

16 { return _len==0; }

References com.cliffc.aa.util.AryInt._len.

Referenced by com.cliffc.aa.type.TypeMem.all_reaching_aliases().

Here is the caller graph for this function:

◆ last()

int com.cliffc.aa.util.AryInt.last ( )
Returns
last element

Definition at line 31 of file AryInt.java.

31  {
32  range_check(0);
33  return _es[_len-1];
34  }

References com.cliffc.aa.util.AryInt._es, com.cliffc.aa.util.AryInt._len, and com.cliffc.aa.util.AryInt.range_check().

Referenced by com.cliffc.aa.util.IBitSet._clr(), com.cliffc.aa.util.IBitSet.max(), and com.cliffc.aa.Parse.skipWS().

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

◆ len()

int com.cliffc.aa.util.AryInt.len ( )
Returns
active list length

Definition at line 18 of file AryInt.java.

18 { return _len; }

References com.cliffc.aa.util.AryInt._len.

Referenced by com.cliffc.aa.util.AryInt.AryInt(), and com.cliffc.aa.util.AryInt.set_len().

Here is the caller graph for this function:

◆ map_update()

AryInt com.cliffc.aa.util.AryInt.map_update ( IntUnaryOperator  f)

Definition at line 120 of file AryInt.java.

120 { for( int i = 0; i<_len; i++ ) _es[i] = f.applyAsInt(_es[i]); return this; }

References com.cliffc.aa.util.AryInt._es, and com.cliffc.aa.util.AryInt._len.

◆ pop()

int com.cliffc.aa.util.AryInt.pop ( )
Returns
remove and return last element

Definition at line 37 of file AryInt.java.

37  {
38  range_check(0);
39  return _es[--_len];
40  }

References com.cliffc.aa.util.AryInt._es, com.cliffc.aa.util.AryInt._len, and com.cliffc.aa.util.AryInt.range_check().

Referenced by com.cliffc.aa.util.IBitSet._clr(), and com.cliffc.aa.type.TypeMem.all_reaching_aliases().

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

◆ push()

AryInt com.cliffc.aa.util.AryInt.push ( int  e)

Add element in amortized constant time.

Parameters
eelement to add at end of list
Returns
'this' for flow-coding

Definition at line 45 of file AryInt.java.

45  {
46  if( _len >= _es.length ) _es = Arrays.copyOf(_es,Math.max(1,_es.length<<1));
47  _es[_len++] = e;
48  return this;
49  }

References com.cliffc.aa.util.AryInt._es, and com.cliffc.aa.util.AryInt._len.

Referenced by com.cliffc.aa.util.AryInt.addAll(), com.cliffc.aa.type.TypeMem.all_reaching_aliases(), com.cliffc.aa.Parse.Parse(), and com.cliffc.aa.Parse.skipWS().

Here is the caller graph for this function:

◆ range_check()

void com.cliffc.aa.util.AryInt.range_check ( int  i)
private

Definition at line 143 of file AryInt.java.

143  {
144  if( i < 0 || i>=_len )
145  throw new ArrayIndexOutOfBoundsException(""+i+" >= "+_len);
146  }

References com.cliffc.aa.util.AryInt._len.

Referenced by com.cliffc.aa.util.AryInt.at(), com.cliffc.aa.util.AryInt.del(), com.cliffc.aa.util.AryInt.last(), com.cliffc.aa.util.AryInt.pop(), com.cliffc.aa.util.AryInt.remove(), and com.cliffc.aa.util.AryInt.set().

Here is the caller graph for this function:

◆ remove()

int com.cliffc.aa.util.AryInt.remove ( int  i)

Slow, linear-time, element removal.

Preserves order.

Parameters
ielement to be removed
Returns
element removed

Definition at line 76 of file AryInt.java.

76  {
77  range_check(i);
78  int e = _es[i];
79  System.arraycopy(_es,i+1,_es,i,(--_len)-i);
80  return e;
81  }

References com.cliffc.aa.util.AryInt._es, com.cliffc.aa.util.AryInt._len, and com.cliffc.aa.util.AryInt.range_check().

Here is the call graph for this function:

◆ set()

int com.cliffc.aa.util.AryInt.set ( int  i,
int  e 
)

Definition at line 93 of file AryInt.java.

93  {
94  range_check(i);
95  return (_es[i] = e);
96  }

References com.cliffc.aa.util.AryInt._es, and com.cliffc.aa.util.AryInt.range_check().

Here is the call graph for this function:

◆ set_as()

AryInt com.cliffc.aa.util.AryInt.set_as ( int  e)

Definition at line 98 of file AryInt.java.

98 { _es[0] = e; _len=1; return this; }

References com.cliffc.aa.util.AryInt._es, and com.cliffc.aa.util.AryInt._len.

◆ set_len()

AryInt com.cliffc.aa.util.AryInt.set_len ( int  len)

Definition at line 99 of file AryInt.java.

99  {
100  if( len > _len )
101  while( len>= _es.length ) _es = Arrays.copyOf(_es,_es.length<<1);
102  _len = len;
103  while( _es.length > (len<<1) ) // Shrink if hugely too large
104  _es = Arrays.copyOf(_es,_es.length>>1);
105  return this;
106  }

References com.cliffc.aa.util.AryInt._es, com.cliffc.aa.util.AryInt._len, and com.cliffc.aa.util.AryInt.len().

Here is the call graph for this function:

◆ setX()

int com.cliffc.aa.util.AryInt.setX ( int  i,
int  e 
)

Definition at line 87 of file AryInt.java.

87  {
88  while( i>= _es.length ) _es = Arrays.copyOf(_es,_es.length<<1);
89  if( i >= _len ) _len = i+1;
90  return (_es[i] = e);
91  }

References com.cliffc.aa.util.AryInt._es, and com.cliffc.aa.util.AryInt._len.

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

Here is the caller graph for this function:

◆ sort_update()

void com.cliffc.aa.util.AryInt.sort_update ( )

Sorts in-place.

Definition at line 126 of file AryInt.java.

126 { Arrays.sort(_es, 0, _len); }

References com.cliffc.aa.util.AryInt._es, and com.cliffc.aa.util.AryInt._len.

◆ toString()

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

Definition at line 136 of file AryInt.java.

136  {
137  SB sb = new SB().p('[');
138  for( int i=0; i<_len; i++ )
139  sb.p(_es[i]).p(',');
140  return sb.unchar().p(']').toString();
141  }

References com.cliffc.aa.util.AryInt._es, com.cliffc.aa.util.AryInt._len, com.cliffc.aa.util.SB.p(), com.cliffc.aa.util.SB.toString(), and com.cliffc.aa.util.SB.unchar().

Here is the call graph for this function:

Member Data Documentation

◆ _es

◆ _len


The documentation for this class was generated from the following file:
com.cliffc.aa.util.AryInt.len
int len()
Definition: AryInt.java:18
com.cliffc.aa.util.AryInt.range_check
void range_check(int i)
Definition: AryInt.java:143
com.cliffc.aa.util.AryInt.AryInt
AryInt()
Definition: AryInt.java:13
com.cliffc.aa.util.AryInt._es
int[] _es
Definition: AryInt.java:9
com.cliffc.aa.util.AryInt.push
AryInt push(int e)
Add element in amortized constant time.
Definition: AryInt.java:45
com.cliffc.aa.util.AryInt._len
int _len
Definition: AryInt.java:10