Ejemplo n.º 1
0
  public static ValueContainer.IntIterator getTransientIterator(
      ValueContainer.IntIterator intIterator) {
    final ValueContainer.IntIterator intIteratorCloned = intIterator.createCopyInInitialState();
    int max = 0, min = Integer.MAX_VALUE;

    while (intIterator.hasNext()) {
      int nextInt = intIterator.next();
      max = Math.max(max, nextInt);
      min = Math.min(min, nextInt);
    }

    assert min > 0;

    final int offset = (min >> INT_BITS_SHIFT) << INT_BITS_SHIFT;
    final int bitsLength = ((max - offset) >> INT_BITS_SHIFT) + 1;
    final int[] bits = ourSpareBuffer.getBuffer(bitsLength);
    for (int i = 0; i < bitsLength; ++i) bits[i] = 0;

    intIterator = intIteratorCloned;
    int size = 0;
    while (intIterator.hasNext()) {
      final int id = intIterator.next() - offset;
      int mask = 1 << id;
      if ((bits[id >> INT_BITS_SHIFT] & mask) == 0) {
        bits[id >> INT_BITS_SHIFT] |= mask;
        ++size;
      }
    }

    return new SortedFileIdSetIterator(bits, bitsLength, offset, size);
  }
Ejemplo n.º 2
0
    private void saveImpl(
        final DataOutput out, final ValueContainer<T> container, final boolean asRemovedData)
        throws IOException {
      DataInputOutputUtil.writeSINT(out, container.size());
      for (final Iterator<T> valueIterator = container.getValueIterator();
          valueIterator.hasNext(); ) {
        final T value = valueIterator.next();
        myExternalizer.save(out, value);

        final ValueContainer.IntIterator ids = container.getInputIdsIterator(value);
        if (ids != null) {
          DataInputOutputUtil.writeSINT(out, ids.size());
          while (ids.hasNext()) {
            final int id = ids.next();
            DataInputOutputUtil.writeSINT(out, asRemovedData ? -id : id);
          }
        } else {
          DataInputOutputUtil.writeSINT(out, 0);
        }
      }
    }