@Override public MappeableContainer iadd(int begin, int end) { int indexstart = BufferUtil.unsignedBinarySearch(content, 0, cardinality, (short) begin); if (indexstart < 0) indexstart = -indexstart - 1; int indexend = BufferUtil.unsignedBinarySearch(content, 0, cardinality, (short) (end - 1)); if (indexend < 0) indexend = -indexend - 1; else indexend++; int rangelength = end - begin; int newcardinality = indexstart + (cardinality - indexend) + rangelength; if (newcardinality > DEFAULT_MAX_SIZE) { MappeableBitmapContainer a = this.toBitmapContainer(); return a.iadd(begin, end); } if (newcardinality >= this.content.limit()) increaseCapacity(newcardinality); BufferUtil.arraycopy( content, indexend, content, indexstart + rangelength, cardinality - indexend); if (BufferUtil.isBackedBySimpleArray(content)) { short[] contentarray = content.array(); for (int k = 0; k < rangelength; ++k) { contentarray[k + indexstart] = (short) (begin + k); } } else { for (int k = 0; k < rangelength; ++k) { content.put(k + indexstart, (short) (begin + k)); } } cardinality = newcardinality; return this; }
@Override public MappeableContainer add(int begin, int end) { int indexstart = BufferUtil.unsignedBinarySearch(content, 0, cardinality, (short) begin); if (indexstart < 0) indexstart = -indexstart - 1; int indexend = BufferUtil.unsignedBinarySearch(content, 0, cardinality, (short) (end - 1)); if (indexend < 0) indexend = -indexend - 1; else indexend++; int rangelength = end - begin; int newcardinality = indexstart + (cardinality - indexend) + rangelength; if (newcardinality > DEFAULT_MAX_SIZE) { MappeableBitmapContainer a = this.toBitmapContainer(); return a.iadd(begin, end); } MappeableArrayContainer answer = new MappeableArrayContainer(newcardinality, content); if (!BufferUtil.isBackedBySimpleArray(answer.content)) throw new RuntimeException("Should not happen. Internal bug."); BufferUtil.arraycopy( content, indexend, answer.content, indexstart + rangelength, cardinality - indexend); short[] answerarray = answer.content.array(); for (int k = 0; k < rangelength; ++k) { answerarray[k + indexstart] = (short) (begin + k); } answer.cardinality = newcardinality; return answer; }
@Override public MappeableContainer iremove(int begin, int end) { int indexstart = BufferUtil.unsignedBinarySearch(content, 0, cardinality, (short) begin); if (indexstart < 0) indexstart = -indexstart - 1; int indexend = BufferUtil.unsignedBinarySearch(content, 0, cardinality, (short) (end - 1)); if (indexend < 0) indexend = -indexend - 1; else indexend++; int rangelength = indexend - indexstart; BufferUtil.arraycopy( content, indexstart + rangelength, content, indexstart, cardinality - indexstart - rangelength); cardinality -= rangelength; return this; }
@Override public MappeableContainer remove(int begin, int end) { int indexstart = BufferUtil.unsignedBinarySearch(content, 0, cardinality, (short) begin); if (indexstart < 0) indexstart = -indexstart - 1; int indexend = BufferUtil.unsignedBinarySearch(content, 0, cardinality, (short) (end - 1)); if (indexend < 0) indexend = -indexend - 1; else indexend++; int rangelength = indexend - indexstart; MappeableArrayContainer answer = clone(); BufferUtil.arraycopy( content, indexstart + rangelength, answer.content, indexstart, cardinality - indexstart - rangelength); answer.cardinality = cardinality - rangelength; return answer; }