static Indices createSortedWithoutCopy(int[] data){ if (data.length == 0) return IndicesFactory.EMPTY_SIMPLE_INDICES; return new SortedIndices(data); } }
@Override public Indices getInverted() { int[] dataInv = new int[data.length]; int fl = data.length - firstLower, i = 0; for (; i < firstLower; ++i) dataInv[fl + i] = data[i] ^ 0x80000000; for (; i < data.length; ++i) dataInv[i - firstLower] = data[i] ^ 0x80000000; return new SortedIndices(dataInv, fl); }
/** * Creates unordered indices from specified integer array of indices. * * @return unordered indices from specified integer array of indices * @throws InconsistentIndicesException if array contains more then one same integer */ public static Indices create(int... data) { if (data.length == 0) return EMPTY_INDICES; return new SortedIndices(data.clone()); } }
@Override public Indices getOfType(IndexType type) { int type_ = type.getType(); int lowerPositionU = Arrays.binarySearch(data, 0, firstLower, (type_ << 24) | 0x80000000); if (lowerPositionU < 0) lowerPositionU = ~lowerPositionU; int upperPositionU = Arrays.binarySearch(data, lowerPositionU, firstLower, ((type_ + 1) << 24) | 0x80000000); if (upperPositionU < 0) upperPositionU = ~upperPositionU; int sizeU = upperPositionU - lowerPositionU; int lowerPositionL = Arrays.binarySearch(data, firstLower, data.length, type_ << 24); if (lowerPositionL < 0) lowerPositionL = ~lowerPositionL; int upperPositionL = Arrays.binarySearch(data, lowerPositionL, data.length, (type_ + 1) << 24); if (upperPositionL < 0) upperPositionL = ~upperPositionL; int sizeL = upperPositionL - lowerPositionL; if (sizeU + sizeL == data.length) return this; else if (sizeU + sizeL == 0) return IndicesFactory.EMPTY_INDICES; int[] indices = new int[sizeU + sizeL]; System.arraycopy(data, lowerPositionU, indices, 0, sizeU); System.arraycopy(data, lowerPositionL, indices, sizeU, sizeL); return new SortedIndices(indices, sizeU); }
@Override public Indices applyIndexMapping(IndexMapping mapping) { boolean changed = false; int newIndex; int[] data_ = data.clone(); for (int i = 0; i < data.length; ++i) if (data_[i] != (newIndex = mapping.map(data_[i]))) { data_[i] = newIndex; changed = true; } if (!changed) return this; return new SortedIndices(data_); }
@Override public Indices getLower() { UpperLowerIndices ul = getUpperLowerIndices(); if (ul.lower.length == 0) return EmptyIndices.EMPTY_INDICES_INSTANCE; return new SortedIndices(ul.lower, 0, new UpperLowerIndices(new int[0], ul.lower)); }
@Override public Indices getUpper() { UpperLowerIndices ul = getUpperLowerIndices(); if (ul.upper.length == 0) return EmptyIndices.EMPTY_INDICES_INSTANCE; return new SortedIndices(ul.upper, ul.upper.length, new UpperLowerIndices(ul.upper, new int[0])); }
/** * Creates unordered indices from specified {@code Indices} object. The resulting indices * will contain exactly the same indices as specified {@code Indices} object, by may have different * terms of ordering, in case when the specified indices are {@link SimpleIndices}. * * @param indices {@code Indices} object * @return unordered indices created from specified {@code Indices} object */ public static Indices create(Indices indices) { if (indices.size() == 0) return EMPTY_INDICES; if (indices instanceof SortedIndices) return indices; return new SortedIndices(indices.getAllIndices().copy()); }