Package org.apache.lucene.util.collections

Examples of org.apache.lucene.util.collections.IntArray


public class IntArrayTest extends LuceneTestCase {
 
  @Test
  public void test0() {
    IntArray array = new IntArray();
   
    assertEquals(0, array.size());
   
    for (int i = 0; i < 100; ++i) {
      array.addToArray(i);
    }
   
    assertEquals(100, array.size());
    for (int i = 0; i < 100; ++i) {
      assertEquals(i, array.get(i));
    }
   
    assertTrue(array.equals(array));
  }
View Full Code Here


    assertTrue(array.equals(array));
  }
 
  @Test
  public void test1() {
    IntArray array = new IntArray();
    IntArray array2 = new IntArray();
   
    assertEquals(0, array.size());
   
    for (int i = 0; i < 100; ++i) {
      array.addToArray(99-i);
      array2.addToArray(99-i);
    }
   
    assertEquals(100, array.size());
    for (int i = 0; i < 100; ++i) {
      assertEquals(i, array.get(99-i));
View Full Code Here

    assertTrue(array.equals(array2));
  }
 
  @Test
  public void test2() {
    IntArray array = new IntArray();
    IntArray array2 = new IntArray();
    IntArray array3 = new IntArray();
   
    for (int i = 0; i < 100; ++i) {
      array.addToArray(i);
    }

    for (int i = 0; i < 100; ++i) {
      array2.addToArray(i*2);
    }

    for (int i = 0; i < 50; ++i) {
      array3.addToArray(i*2);
    }

    assertFalse(array.equals(array2));
   
    array.intersect(array2);
View Full Code Here

  @Test
  public void testSet() {
    int[] original = new int[] { 2,4,6,8,10,12,14 };
    int[] toSet = new int[] { 1,3,5,7,9,11};
   
    IntArray arr = new IntArray();
    for (int val : original) {
      arr.addToArray(val);
    }
   
    for (int i = 0; i < toSet.length; i++ ) {
      int val = toSet[i];
      arr.set(i, val);
    }
   
    // Test to see if the set worked correctly
    for (int i = 0; i < toSet.length; i++ ) {
      assertEquals(toSet[i], arr.get(i));
    }
   
    // Now attempt to set something outside of the array
    try {
      arr.set(100, 99);
      fail("IntArray.set should have thrown an exception for attempting to set outside the array");
    } catch (ArrayIndexOutOfBoundsException e) {
      // We expected this to happen so let it fall through
      // silently
    }
View Full Code Here

      FacetIndexingParams iparams, CategoryListParams clp) throws IOException {
 
    final int maxDoc = reader.maxDoc();
    int[][][]dpf  = new int[maxDoc][][];
    int numPartitions = (int)Math.ceil(taxo.getSize()/(double)iparams.getPartitionSize());
    IntArray docCategories = new IntArray();
    for (int part=0; part<numPartitions; part++) {
      CategoryListIterator cli = clp.createCategoryListIterator(reader, part);
      if (cli.init()) {
        for (int doc=0; doc<maxDoc; doc++) {
          if (cli.skipTo(doc)) {
            docCategories.clear(false);
            if (dpf[doc]==null) {
              dpf[doc] = new int[numPartitions][];
            }
            long category;
            while ((category = cli.nextCategory()) <= Integer.MAX_VALUE) {
              docCategories.addToArray((int)category);
            }
            final int size = docCategories.size();
            dpf[doc][part] = new int[size];
            for (int i=0; i<size; i++) {
              dpf[doc][part][i] = docCategories.get(i);
            }
          }
        }
      }
    }
View Full Code Here

TOP

Related Classes of org.apache.lucene.util.collections.IntArray

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.