Go to the documentation of this file. 1 package com.cliffc.aa.util;
3 import java.util.Arrays;
4 import java.util.Collection;
5 import java.util.function.IntUnaryOperator;
11 public AryInt(
int[] es) {
this(es,es.length); }
13 public AryInt() {
this(
new int[1],0); }
21 public int at(
int i ) {
27 public int atX(
int i ) {
57 throw new ArrayIndexOutOfBoundsException(
""+i+
" >= "+
_len);
66 public int del(
int i ) {
76 public int remove(
int i ) {
87 public int setX(
int i,
int e ) {
88 while( i>=
_es.length )
_es = Arrays.copyOf(
_es,
_es.length<<1);
93 public int set(
int i,
int e ) {
103 while(
_es.length > (
len<<1) )
109 public AryInt addAll( Collection<? extends Integer> c ) {
for(
int e : c )
push(e);
return this; }
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);
132 for(
int i=0; i<
_len; i++ )
if(
_es[i]==e )
return i;
137 SB sb =
new SB().
p(
'[');
138 for(
int i=0; i<
_len; i++ )
144 if( i < 0 || i>=
_len )
145 throw new ArrayIndexOutOfBoundsException(
""+i+
" >= "+
_len);
153 int mid = (hi + lo) >>> 1;
157 while( mid>0 && e==
_es[mid-1] ) mid--;
160 if( e >mval ) lo = mid+1;
169 @Override
public boolean equals( Object o ) {
170 if(
this==o )
return true;
171 if( !(o instanceof
AryInt) )
return false;
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] )
182 for(
int i=0; i<
_len; i++ )
void insert(int i, int e)
Slow, linear-time, element insert.
void sort_update()
Sorts in-place.
int find(int e)
Find the first matching element using ==, or -1 if none.
AryInt push(int e)
Add element in amortized constant time.
Tight/tiny StringBuilder wrapper.
AryInt(int[] es, int len)
AryInt addAll(Collection<? extends Integer > c)
void clear()
Remove all elements.
int del(int i)
Fast, constant-time, element removal.
AryInt map_update(IntUnaryOperator f)