| 1 | |
|
| 2 | |
|
| 3 | |
package org.galagosearch.core.util; |
| 4 | |
|
| 5 | |
public class IntArray { |
| 6 | |
int[] _array; |
| 7 | |
int _position; |
| 8 | |
|
| 9 | 0 | public IntArray(int capacity) { |
| 10 | 0 | _array = new int[capacity]; |
| 11 | 0 | _position = 0; |
| 12 | 0 | } |
| 13 | |
|
| 14 | |
public IntArray() { |
| 15 | 0 | this(16); |
| 16 | 0 | } |
| 17 | |
|
| 18 | |
public void add(int value) { |
| 19 | 0 | if(_position == _array.length) { |
| 20 | |
|
| 21 | 0 | _array = _copyArray(_array.length * 2); |
| 22 | |
} |
| 23 | |
|
| 24 | 0 | _array[_position] = value; |
| 25 | 0 | _position += 1; |
| 26 | 0 | } |
| 27 | |
|
| 28 | |
public int[] getBuffer() { |
| 29 | 0 | return _array; |
| 30 | |
} |
| 31 | |
|
| 32 | |
public int getPosition() { |
| 33 | 0 | return _position; |
| 34 | |
} |
| 35 | |
|
| 36 | |
private int[] _copyArray(int newSize) { |
| 37 | 0 | int[] result = new int[newSize]; |
| 38 | 0 | System.arraycopy(_array, 0, result, 0, _position); |
| 39 | 0 | return result; |
| 40 | |
} |
| 41 | |
|
| 42 | |
public int[] toArray() { |
| 43 | 0 | return _copyArray(_position); |
| 44 | |
} |
| 45 | |
} |