summaryrefslogtreecommitdiff
path: root/src/main/java/com/seaofnodes/simple/Ary.java
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2024-11-26 11:01:47 -0800
committerCliff Click <cliffc@acm.org>2025-01-14 15:17:03 -0800
commiteee5b806fabae0b480ff7d41159369c5a457d014 (patch)
tree576e6ed318eea76aa9e0de9e95af7616a0b8475a /src/main/java/com/seaofnodes/simple/Ary.java
parentc07510c1d75020d23d688f7f184149c57b13a39a (diff)
downloadSimple-linear-chapter18.tar.gz
Simple-linear-chapter18.zip
Chapter 18: Functionslinear-chapter18
Diffstat (limited to 'src/main/java/com/seaofnodes/simple/Ary.java')
-rw-r--r--src/main/java/com/seaofnodes/simple/Ary.java36
1 files changed, 10 insertions, 26 deletions
diff --git a/src/main/java/com/seaofnodes/simple/Ary.java b/src/main/java/com/seaofnodes/simple/Ary.java
index 8654d41e..b5184948 100644
--- a/src/main/java/com/seaofnodes/simple/Ary.java
+++ b/src/main/java/com/seaofnodes/simple/Ary.java
@@ -57,18 +57,6 @@ public class Ary<E> extends AbstractList<E> implements List<E> {
return true;
}
- ///** Slow, linear-time, element insert. Preserves order.
- // * @param i index to insert at, between 0 and _len inclusive.
- // * @param e Element to insert
- // */
- //public void insert( int i, E e ) {
- // if( i < 0 || i>_len )
- // throw new ArrayIndexOutOfBoundsException(""+i+" >= "+_len);
- // if( _len >= _es.length ) _es = Arrays.copyOf(_es,Math.max(1,_es.length<<1));
- // System.arraycopy(_es,i,_es,i+1,(_len++)-i);
- // _es[i] = e;
- //}
-
/** Fast, constant-time, element removal. Does not preserve order
* @param i element to be removed
* @return element removed */
@@ -79,20 +67,6 @@ public class Ary<E> extends AbstractList<E> implements List<E> {
return tmp;
}
- ///** Element removal, using '=='. Does not preserve order.
- // * @param e element to be removed
- // * @return element removed */
- //public E del( E e ) {
- // for( int i=0; i<_len; i++ ) {
- // E tmp = _es[i];
- // if( tmp==e ) {
- // _es[i]=_es[--_len];
- // return tmp;
- // }
- // }
- // return null;
- //}
-
/** Slow, linear-time, element removal. Preserves order.
* @param i element to be removed
* @return element removed */
@@ -129,6 +103,16 @@ public class Ary<E> extends AbstractList<E> implements List<E> {
return this;
}
+ public void swap( int i, int j ) {
+ range_check(i);
+ range_check(j);
+ if( i==j ) return;
+ E tmp = _es[i];
+ _es[i] = _es[j];
+ _es[j] = tmp;
+ }
+
+
/** @param c Collection to be added */
public boolean addAll( Collection<? extends E> c ) {
if( c==null ) return false;