Package com.metamx.collections.bitmap

Source Code of com.metamx.collections.bitmap.WrappedImmutableRoaringBitmap

package com.metamx.collections.bitmap;

import org.roaringbitmap.IntIterator;
import org.roaringbitmap.buffer.ImmutableRoaringBitmap;

import java.nio.ByteBuffer;

public class WrappedImmutableRoaringBitmap implements ImmutableGenericBitmap
{
  /**
   * Underlying bitmap.
   */
  private final ImmutableRoaringBitmap invertedIndex;

  protected WrappedImmutableRoaringBitmap(ByteBuffer byteBuffer)
  {
    this.invertedIndex = new ImmutableRoaringBitmap(byteBuffer.asReadOnlyBuffer());
  }

  /**
   * Wrap an ImmutableRoaringBitmap
   *
   * @param immutableRoaringBitmap bitmap to be wrapped
   */
  public WrappedImmutableRoaringBitmap(ImmutableRoaringBitmap immutableRoaringBitmap)
  {
    this.invertedIndex = immutableRoaringBitmap;
  }

  public ImmutableRoaringBitmap getInvertedIndex()
  {
    return invertedIndex;
  }

  @Override
  public String toString()
  {
    return getClass().getSimpleName() + invertedIndex.toString();
  }

  @Override
  public IntIterator iterator()
  {
    return invertedIndex.getIntIterator();
  }

  @Override
  public int size()
  {
    return invertedIndex.getCardinality();
  }

  @Override
  public boolean isEmpty()
  {
    return invertedIndex.isEmpty();
  }

  @Override
  public ImmutableGenericBitmap union(ImmutableGenericBitmap bitmap)
  {
    WrappedImmutableRoaringBitmap other = (WrappedImmutableRoaringBitmap) bitmap;
    ImmutableRoaringBitmap otherIndex = other.invertedIndex;
    return new WrappedImmutableRoaringBitmap(ImmutableRoaringBitmap.or(invertedIndex, otherIndex));
  }

  @Override
  public ImmutableGenericBitmap intersection(ImmutableGenericBitmap bitmap)
  {
    WrappedImmutableRoaringBitmap other = (WrappedImmutableRoaringBitmap) bitmap;
    ImmutableRoaringBitmap otherIndex = other.invertedIndex;
    return new WrappedImmutableRoaringBitmap(ImmutableRoaringBitmap.and(invertedIndex, otherIndex));
  }

  @Override
  public ImmutableGenericBitmap difference(ImmutableGenericBitmap bitmap)
  {
    WrappedImmutableRoaringBitmap other = (WrappedImmutableRoaringBitmap) bitmap;
    ImmutableRoaringBitmap otherIndex = other.invertedIndex;
    return new WrappedImmutableRoaringBitmap(ImmutableRoaringBitmap.andNot(invertedIndex, otherIndex));
  }
}
TOP

Related Classes of com.metamx.collections.bitmap.WrappedImmutableRoaringBitmap

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.