Package com.metamx.collections.bitmap

Examples of com.metamx.collections.bitmap.MutableBitmap


          GenericIndexed<ImmutableBitmap> bitmaps = bitmapIndexes.get(dimension);
          ImmutableRTree spatialIndex = spatialIndexes.get(dimension);

          final BitmapFactory bitmapFactory = bitmapSerdeFactory.getBitmapFactory();
          boolean onlyOneValue = true;
          MutableBitmap nullsSet = null;
          for (int i = 0; i < multiValCol.size(); ++i) {
            VSizeIndexedInts rowValue = multiValCol.get(i);
            if (!onlyOneValue) {
              break;
            }
            if (rowValue.size() > 1) {
              onlyOneValue = false;
            }
            if (rowValue.size() == 0) {
              if (nullsSet == null) {
                nullsSet = bitmapFactory.makeEmptyMutableBitmap();
              }
              nullsSet.add(i);
            }
          }

          if (onlyOneValue) {
            log.info("Dimension[%s] is single value, converting...", dimension);
View Full Code Here


  @BenchmarkOptions(warmupRounds = 10, benchmarkRounds = 1000)
  @Test
  public void testLinearAddition()
  {
    MutableBitmap mutableBitmap = factory.makeEmptyMutableBitmap();
    for (int i = 0; i < numBits; ++i) {
      mutableBitmap.add(i);
    }
    Assert.assertEquals(numBits, mutableBitmap.size());
  }
View Full Code Here

  @BenchmarkOptions(warmupRounds = 10, benchmarkRounds = 10)
  @Test
  public void testRandomAddition()
  {
    MutableBitmap mutableBitmap = factory.makeEmptyMutableBitmap();
    for (int i : randIndex) {
      mutableBitmap.add(i);
    }
    Assert.assertEquals(numBits, mutableBitmap.size());
  }
View Full Code Here

  @BenchmarkOptions(warmupRounds = 10, benchmarkRounds = 1000)
  @Test
  public void testLinearAdditionDescending()
  {
    MutableBitmap mutableBitmap = factory.makeEmptyMutableBitmap();
    for (int i = numBits - 1; i >= 0; --i) {
      mutableBitmap.add(i);
    }
    Assert.assertEquals(numBits, mutableBitmap.size());
  }
View Full Code Here

                  indexes.get(j).getBitmapIndex(dimension, dimVal), rowNumConversions.get(j)
              )
          );
        }

        MutableBitmap bitset = bitmapSerdeFactory.getBitmapFactory().makeEmptyMutableBitmap();
        for (Integer row : CombiningIterable.createSplatted(
            convertedInverteds,
            Ordering.<Integer>natural().nullsFirst()
        )) {
          if (row != INVALID_ROW) {
            bitset.add(row);
          }
        }

        writer.write(
            bitmapSerdeFactory.getBitmapFactory().makeImmutableBitmap(bitset)
View Full Code Here

    ColumnDictionaryEntryStore adder = hasMultipleValues
                                       ? new MultiValColumnDictionaryEntryStore()
                                       : new SingleValColumnDictionaryEntryStore();

    final BitmapFactory bitmapFactory = bitmapSerdeFactory.getBitmapFactory();
    MutableBitmap nullSet = null;
    int rowCount = 0;

    for (Rowboat theRow : theRows) {
      if (dimIndex > theRow.getDims().length) {
        if (nullSet == null) {
          nullSet = bitmapFactory.makeEmptyMutableBitmap();
        }
        nullSet.add(rowCount);
        adder.add(null);
      } else {
        int[] dimVals = theRow.getDims()[dimIndex];
        if (dimVals == null || dimVals.length == 0) {
          if (nullSet == null) {
            nullSet = bitmapFactory.makeEmptyMutableBitmap();
          }
          nullSet.add(rowCount);
        }
        adder.add(dimVals);
      }
      rowCount++;
    }

    final Iterable<String> dimensionValues = dimensionValuesLookup.get(dimension);
    GenericIndexed<String> dictionary = GenericIndexed.fromIterable(
        dimensionValues,
        GenericIndexed.stringStrategy
    );
    boolean bumpDictionary = false;

    if (hasMultipleValues) {
      final List<List<Integer>> vals = ((MultiValColumnDictionaryEntryStore) adder).get();
      if (nullSet != null) {
        log.info("Dimension[%s] has null rows.", dimension);

        if (Iterables.getFirst(dimensionValues, "") != null) {
          bumpDictionary = true;
          log.info("Dimension[%s] has no null value in the dictionary, expanding...", dimension);

          final List<String> nullList = Lists.newArrayList();
          nullList.add(null);

          dictionary = GenericIndexed.fromIterable(
              Iterables.concat(nullList, dimensionValues),
              GenericIndexed.stringStrategy
          );

          final int dictionarySize = dictionary.size();
          multiValCol = VSizeIndexed.fromIterable(
              FunctionalIterable
                  .create(vals)
                  .transform(
                      new Function<List<Integer>, VSizeIndexedInts>()
                      {
                        @Override
                        public VSizeIndexedInts apply(final List<Integer> input)
                        {
                          if (input == null) {
                            return VSizeIndexedInts.fromList(
                                new AbstractList<Integer>()
                                {
                                  @Override
                                  public Integer get(int index)
                                  {
                                    return 0;
                                  }

                                  @Override
                                  public int size()
                                  {
                                    return 1;
                                  }
                                }, dictionarySize
                            );
                          }
                          return VSizeIndexedInts.fromList(
                              new AbstractList<Integer>()
                              {
                                @Override
                                public Integer get(int index)
                                {
                                  Integer val = input.get(index);
                                  if (val == null) {
                                    return 0;
                                  }
                                  return val + 1;
                                }

                                @Override
                                public int size()
                                {
                                  return input.size();
                                }
                              },
                              dictionarySize
                          );
                        }
                      }
                  )
          );
        } else {
          final int dictionarySize = dictionary.size();
          multiValCol = VSizeIndexed.fromIterable(
              FunctionalIterable
                  .create(vals)
                  .transform(
                      new Function<List<Integer>, VSizeIndexedInts>()
                      {
                        @Override
                        public VSizeIndexedInts apply(List<Integer> input)
                        {
                          if (input == null) {
                            return VSizeIndexedInts.fromList(
                                new AbstractList<Integer>()
                                {
                                  @Override
                                  public Integer get(int index)
                                  {
                                    return 0;
                                  }

                                  @Override
                                  public int size()
                                  {
                                    return 1;
                                  }
                                }, dictionarySize
                            );
                          }
                          return VSizeIndexedInts.fromList(
                              input,
                              dictionarySize
                          );
                        }
                      }
                  )
          );
        }
      } else {
        final int dictionarySize = dictionary.size();
        multiValCol = VSizeIndexed.fromIterable(
            FunctionalIterable
                .create(vals)
                .transform(
                    new Function<List<Integer>, VSizeIndexedInts>()
                    {
                      @Override
                      public VSizeIndexedInts apply(List<Integer> input)
                      {
                        return VSizeIndexedInts.fromList(
                            input,
                            dictionarySize
                        );
                      }
                    }
                )
        );
      }
    } else {
      final List<Integer> vals = ((SingleValColumnDictionaryEntryStore) adder).get();

      if (nullSet != null) {
        log.info("Dimension[%s] has null rows.", dimension);

        if (Iterables.getFirst(dimensionValues, "") != null) {
          bumpDictionary = true;
          log.info("Dimension[%s] has no null value in the dictionary, expanding...", dimension);

          final List<String> nullList = Lists.newArrayList();
          nullList.add(null);

          dictionary = GenericIndexed.fromIterable(
              Iterables.concat(nullList, dimensionValues),
              GenericIndexed.stringStrategy
          );
          singleValCol = VSizeIndexedInts.fromList(
              new AbstractList<Integer>()
              {
                @Override
                public Integer get(int index)
                {
                  Integer val = vals.get(index);
                  if (val == null) {
                    return 0;
                  }
                  return val + 1;
                }

                @Override
                public int size()
                {
                  return vals.size();
                }
              }, dictionary.size()
          );
        } else {
          singleValCol = VSizeIndexedInts.fromList(
              new AbstractList<Integer>()
              {
                @Override
                public Integer get(int index)
                {
                  Integer val = vals.get(index);
                  if (val == null) {
                    return 0;
                  }
                  return val;
                }

                @Override
                public int size()
                {
                  return vals.size();
                }
              }, dictionary.size()
          );
        }
      } else {
        singleValCol = VSizeIndexedInts.fromList(vals, dictionary.size());
      }
    }

    // Make bitmap indexes
    List<MutableBitmap> mutableBitmaps = Lists.newArrayList();
    for (String dimVal : dimensionValues) {
      List<Iterable<Integer>> convertedInverteds = Lists.newArrayListWithCapacity(adapters.size());
      for (int j = 0; j < adapters.size(); ++j) {
        convertedInverteds.add(
            new ConvertingIndexedInts(
                adapters.get(j).getBitmapIndex(dimension, dimVal), rowNumConversions.get(j)
            )
        );
      }

      MutableBitmap bitset = bitmapSerdeFactory.getBitmapFactory().makeEmptyMutableBitmap();
      for (Integer row : CombiningIterable.createSplatted(
          convertedInverteds,
          Ordering.<Integer>natural().nullsFirst()
      )) {
        if (row != INVALID_ROW) {
          bitset.add(row);
        }
      }

      mutableBitmaps.add(bitset);
    }
View Full Code Here

        if (dimIndex >= dims.length || dims[dimIndex] == null) {
          continue;
        }

        for (String dimValue : dims[dimIndex]) {
          MutableBitmap mutableBitmap = bitmapIndexes.get(dimValue);

          if (mutableBitmap == null) {
            mutableBitmap = bitmapFactory.makeEmptyMutableBitmap();
            bitmapIndexes.put(dimValue, mutableBitmap);
          }

          try {
            mutableBitmap.add(rowNum);
          }
          catch (Exception e) {
            log.info(e.toString());
          }
        }
View Full Code Here

    if (dimInverted == null) {
      return new EmptyIndexedInts();
    }

    final MutableBitmap bitmapIndex = dimInverted.get(value);

    if (bitmapIndex == null) {
      return new EmptyIndexedInts();
    }

    return new IndexedInts()
    {
      @Override
      public int size()
      {
        return bitmapIndex.size();
      }

      @Override
      public int get(int index)
      {
        throw new UnsupportedOperationException("This is really slow, so it's just not supported.");
      }

      @Override
      public Iterator<Integer> iterator()
      {
        return new Iterator<Integer>()
        {
          IntIterator baseIter = bitmapIndex.iterator();

          @Override
          public boolean hasNext()
          {
            return baseIter.hasNext();
View Full Code Here

TOP

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

Copyright © 2018 www.massapicom. 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.