| 33 | import java.util.Arrays; |
| 34 | |
| 35 | public class LongList implements Mutable, LongVec, Sinkable { |
| 36 | private static final int DEFAULT_ARRAY_SIZE = 16; |
| 37 | private static final long DEFAULT_NO_ENTRY_VALUE = -1L; |
| 38 | private final int initialCapacity; |
| 39 | private final long noEntryValue; |
| 40 | private long[] data; |
| 41 | private int pos = 0; |
| 42 | |
| 43 | public LongList() { |
| 44 | this(DEFAULT_ARRAY_SIZE); |
| 45 | } |
| 46 | |
| 47 | public LongList(int capacity) { |
| 48 | this(capacity, DEFAULT_NO_ENTRY_VALUE); |
| 49 | } |
| 50 | |
| 51 | public LongList(int capacity, long noEntryValue) { |
| 52 | this.initialCapacity = capacity; |
| 53 | this.data = new long[capacity]; |
| 54 | this.noEntryValue = noEntryValue; |
| 55 | } |
| 56 | |
| 57 | public LongList(LongList other) { |
| 58 | this.initialCapacity = Math.max(other.size(), DEFAULT_ARRAY_SIZE); |
| 59 | this.data = new long[initialCapacity]; |
| 60 | setPos(other.size()); |
| 61 | System.arraycopy(other.data, 0, this.data, 0, pos); |
| 62 | this.noEntryValue = other.noEntryValue; |
| 63 | } |
| 64 | |
| 65 | public LongList(long[] other) { |
| 66 | this.initialCapacity = other.length; |
| 67 | this.data = new long[initialCapacity]; |
| 68 | setPos(other.length); |
| 69 | System.arraycopy(other, 0, this.data, 0, pos); |
| 70 | this.noEntryValue = DEFAULT_NO_ENTRY_VALUE; |
| 71 | } |
| 72 | |
| 73 | public void add(long value) { |
| 74 | checkCapacity(pos + 1); |
| 75 | data[pos++] = value; |
| 76 | } |
| 77 | |
| 78 | public void add(long value0, long value1) { |
| 79 | int n = pos; |
| 80 | checkCapacity(n + 2); |
| 81 | data[n++] = value0; |
| 82 | data[n++] = value1; |
| 83 | pos = n; |
| 84 | } |
| 85 | |
| 86 | public void add(long value0, long value1, long value2, long value3) { |
| 87 | int n = pos; |
| 88 | checkCapacity(n + 4); |
| 89 | data[n++] = value0; |
| 90 | data[n++] = value1; |
| 91 | data[n++] = value2; |
| 92 | data[n++] = value3; |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…