/** * Returns a new IntColumn containing a value for each value in this column, truncating if necessary. * * A narrowing primitive conversion such as this one may lose information about the overall magnitude of a * numeric value and may also lose precision and range. Specifically, if the value is too small (a negative value * of large magnitude or negative infinity), the result is the smallest representable value of type int. * * Similarly, if the value is too large (a positive value of large magnitude or positive infinity), the result is the * largest representable value of type int. * * Despite the fact that overflow, underflow, or other loss of information may occur, a narrowing primitive * conversion never results in a run-time exception. * * A missing value in the receiver is converted to a missing value in the result */ @Override public ShortColumn asShortColumn() { ShortArrayList values = new ShortArrayList(); for (float d : data) { values.add((short) d); } values.trim(); return ShortColumn.create(this.name(), values.elements()); }
@Override public Selection selectIsIn(Collection<String> strings) { ShortOpenHashSet keys = new ShortOpenHashSet(strings.size()); for (String string : strings) { short key = getKeyForValue(string); if (key != DEFAULT_RETURN_VALUE) { keys.add(key); } } Selection results = new BitmapBackedSelection(); for (int i = 0; i < values.size(); i++) { if (keys.contains(values.getShort(i))) { results.add(i); } } return results; }
@Override public ShortColumn bottom(final int n) { final ShortArrayList bottom = new ShortArrayList(); final short[] values = data.toShortArray(); ShortArrays.parallelQuickSort(values); for (int i = 0; i < n && i < values.length; i++) { bottom.add(values[i]); } return new ShortColumn(name() + "[Bottoms " + n + "]", bottom); }
@Override public void sortAscending() { short[] elements = values.toShortArray(); ShortArrays.parallelQuickSort(elements, dictionarySortComparator); this.values = new ShortArrayList(elements); }
public static ShortColumn create(final String name) { return new ShortColumn(name, new ShortArrayList()); }
public ShortColumn append(short i) { data.add(i); return this; }
/** * Returns the number of elements (a.k.a. rows or cells) in the column * * @return size as int */ @Override public int size() { return values.size(); }
@Override public int getKeyForIndex(int rowIndex) { return values.getShort(rowIndex); }
/** * Pours an iterator, returning a type-specific list, with a limit on the number * of elements. * * <p> * This method iterates over the given type-specific iterator and returns a * type-specific list containing the returned elements (up to {@code max}). * Iteration on the returned list is guaranteed to produce the elements in the * same order in which they appeared in the iterator. * * * @param i * a type-specific iterator. * @param max * the maximum number of elements to be poured. * @return a type-specific list containing the returned elements, up to * {@code max}. */ public static ShortList pour(final ShortIterator i, int max) { final ShortArrayList l = new ShortArrayList(); pour(i, l, max); l.trim(); return l; } /**
private short chooseMinLabelPartition(short currentPartition) { short newPartition; if (maxIndices.size() == 1) { newPartition = maxIndices.get(0); } else { if (maxIndices.contains(currentPartition)) { newPartition = currentPartition; } else { newPartition = maxIndices.get(0); } } return newPartition; }
@Override public void seal() { ((ShortArrayList) _innerList).trim(); _elements = ((ShortArrayList) _innerList).elements(); int negativeIndexCheck = withDummy ? 1 : 0; // reverse negative elements, because string order and numeric orders are completely opposite if (_elements.length > negativeIndexCheck && _elements[negativeIndexCheck] < 0) { int endPosition = indexOfWithType((short) 0); if (endPosition < 0) { endPosition = -1 * endPosition - 1; } short tmp; for (int i = 0; i < (endPosition - negativeIndexCheck) / 2; i++) { tmp = _elements[i + negativeIndexCheck]; _elements[i + negativeIndexCheck] = _elements[endPosition - i - 1]; _elements[endPosition - i - 1] = tmp; } } }
@Override public void sortDescending() { ShortArrays.parallelQuickSort(data.elements(), descendingComparator); }
public ShortColumn set(int i, short val) { data.set(i, val); return this; }
private void serializeList(final DataOutput out, final List list) throws IOException { Class oCls = list.getClass(); if (oCls.equals(IntArrayList.class)) { serialize(out, ((IntArrayList) list).toIntArray()); } else if (oCls.equals(FloatArrayList.class)) { serialize(out, ((FloatArrayList) list).toFloatArray()); } else if (oCls.equals(DoubleArrayList.class)) { serialize(out, ((DoubleArrayList) list).toDoubleArray()); } else if (oCls.equals(ShortArrayList.class)) { serialize(out, ((ShortArrayList) list).toShortArray()); } else if (oCls.equals(ByteArrayList.class)) { serialize(out, ((ByteArrayList) list).toByteArray()); } else if (oCls.equals(LongArrayList.class)) { serialize(out, ((LongArrayList) list).toLongArray()); } else if (oCls.equals(BooleanArrayList.class)) { serialize(out, ((BooleanArrayList) list).toBooleanArray()); } else if (oCls.equals(CharArrayList.class)) { serialize(out, ((CharArrayList) list).toCharArray()); } else { serialize(out, list.size()); for (Object obj : list) { serialize(out, obj); } } }
@Override public void clear() { data.clear(); }
/** * Trims this array list so that the capacity is equal to the size. * * @see java.util.ArrayList#trimToSize() */ public void trim() { trim(0); } /**
@Override public void sortDescending() { short[] elements = values.toShortArray(); ShortArrays.parallelQuickSort(elements, reverseDictionarySortComparator); this.values = new ShortArrayList(elements); }
public static ShortColumn create(final String name, final short[] arr) { return new ShortColumn(name, new ShortArrayList(arr)); }