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