Package it.unimi.dsi.fastutil.longs

Examples of it.unimi.dsi.fastutil.longs.LongList


      sizes = queryProperties != null && queryProperties.containsKey( UriKeys.SUCCINCTSIZES ) ? readSizesSuccinct( basename + DiskBasedIndex.SIZES_EXTENSION, numberOfDocuments ) : readSizes( basename + DiskBasedIndex.SIZES_EXTENSION, numberOfDocuments );
      if ( sizes.size() != numberOfDocuments ) throw new IllegalStateException( "The length of the size list (" + sizes.size() + ") is not equal to the number of documents (" + numberOfDocuments + ")" );
    }
   
    // Load offsets if forced to do so. Depending on a property, we use the core-memory or the semi-external version.
    final LongList offsets;
    // TODO: quick patch to avoid loading sizes in case of payloads.
    if ( payload == null && randomAccess ) {
      int offsetStep = queryProperties != null && queryProperties.get( UriKeys.OFFSETSTEP ) != null ? Integer.parseInt( queryProperties.get( UriKeys.OFFSETSTEP ) ) : DEFAULT_OFFSET_STEP;
     
      if ( offsetStep < 0 ) { // Memory-mapped
        offsetStep  = -offsetStep;
        offsets = LongLists.synchronize( new SemiExternalOffsetList(
            new InputBitStream( ByteBufferInputStream.map( new FileInputStream( basename + DiskBasedIndex.OFFSETS_EXTENSION ).getChannel(), MapMode.READ_ONLY ) ),
            offsetStep, numberOfTerms + 1 ) );
      }
      else {
        offsets = offsetStep == 0?
            DiskBasedIndex.readOffsets( basename + DiskBasedIndex.OFFSETS_EXTENSION, numberOfTerms ) :
              LongLists.synchronize( new SemiExternalOffsetList( new InputBitStream( basename + DiskBasedIndex.OFFSETS_EXTENSION, 1024 ), offsetStep, numberOfTerms + 1 ) );
      }
      if ( offsets.size() != numberOfTerms + 1 ) throw new IllegalStateException( "The length of the offset list (" + offsets.size() + ") is not equal to the number of terms plus one (" + numberOfTerms + " + 1)" );
    }
    else offsets = null;
   
   
    final int quantum = properties.getInt( BitStreamIndex.PropertyKeys.SKIPQUANTUM, -1 );
View Full Code Here


 
    public void testSemiExternalOffsetListGammaCoding() throws IOException {

    long[] offsets = { 10, 300, 450, 650, 1000, 1290, 1699 };
    LongList listOffsets = new LongArrayList( offsets );

    SemiExternalOffsetList list = new SemiExternalOffsetList( buildInputStream( listOffsets ), 1, listOffsets.size() );
    for ( int i = 0; i < offsets.length; ++i ) {
      assertEquals( ( "test failed for index: " + i ), offsets[ i ], list.getLong( i ) );
    }

    list = new SemiExternalOffsetList( buildInputStream( listOffsets ), 2, listOffsets.size() );
    for ( int i = 0; i < offsets.length; ++i ) {
      assertEquals( ( "test failed for index: " + i ), offsets[ i ], list.getLong( i ) );
    }

    list = new SemiExternalOffsetList( buildInputStream( listOffsets ), 4, listOffsets.size() );
    for ( int i = 0; i < offsets.length; ++i ) {
      assertEquals( ( "test failed for index: " + i ), offsets[ i ], list.getLong( i ) );
    }

    list = new SemiExternalOffsetList( buildInputStream( listOffsets ), 7, listOffsets.size() );
    for ( int i = 0; i < offsets.length; ++i ) {
      assertEquals( ( "test failed for index: " + i ), offsets[ i ], list.getLong( i ) );
    }
   
    list = new SemiExternalOffsetList( buildInputStream( listOffsets ), 8, listOffsets.size() );
    for ( int i = 0; i < offsets.length; ++i ) {
      assertEquals( ( "test failed for index: " + i ), offsets[ i ], list.getLong( i ) );
    }
    }
View Full Code Here

    }

    public void testEmptySemiExternalOffsetListGammaCoding() throws IOException {

    long[] offsets = {  };
    LongList listOffsets = new LongArrayList( offsets );

    new SemiExternalOffsetList( buildInputStream( listOffsets ), 1, listOffsets.size() );
    assertTrue( true );
    }
View Full Code Here

    ZoieSystem<IndexReader,DocumentWithID> zoie = zoieHome.getZoieSystem();
    if (zoie==null){
      throw new IOException("zoie is not setup");
    }

    final LongList delList = new LongArrayList();
   
    List<ZoieIndexReader<IndexReader>> readerList = null;
    IndexSearcher searcher = null;
    try{
      readerList = zoie.getIndexReaders();
      MultiReader reader = new MultiReader(readerList.toArray(new IndexReader[readerList.size()]), false);
      searcher = new IndexSearcher(reader);
      searcher.search(q, new Collector(){
        ZoieIndexReader<IndexReader> zoieReader = null;
        int base = 0;
        @Override
        public boolean acceptsDocsOutOfOrder() {
          return true;
        }

        @Override
        public void collect(int doc) throws IOException {
          long uid = zoieReader.getUID(doc+base);
          if (uid!=DocIDMapper.NOT_FOUND){
            delList.add(uid);
          }
        }

        @Override
        public void setNextReader(IndexReader reader, int base)
            throws IOException {
          zoieReader = (ZoieIndexReader<IndexReader>)reader;
          this.base = base;
        }

        @Override
        public void setScorer(Scorer scorer) throws IOException {
         
        }
       
      });
     
     
     
    }
    finally{
      try{
        if (searcher!=null){
        searcher.close();
        }
      }
      finally{
           if (readerList!=null){
        zoie.returnIndexReaders(readerList);
        }
      }
    }
   
    if (delList.size()>0){
      long version = zoie.getCurrentVersion();
      ArrayList<DataEvent<DocumentWithID>> eventList = new ArrayList<DataEvent<DocumentWithID>>(delList.size());
      for (long val : delList){
        eventList.add(new DataEvent<DocumentWithID>(version,new DocumentWithID(val,true)));
      }
      try {
        zoie.consume(eventList);
View Full Code Here

   * Constructs with the given input.
   *
   * @param indexInputSupplier Provides {@link InputStream} for reading the index.
   */
  StreamDataFileIndex(InputSupplier<? extends InputStream> indexInputSupplier) {
    LongList timestamps;
    LongList positions;

    // Load the whole index into memory.
    try {
      Map.Entry<LongList, LongList> index;
      InputStream indexInput = indexInputSupplier.getInput();
View Full Code Here

    // Decode the properties map. In current version, it is not used.
    StreamUtils.decodeMap(new BinaryDecoder(input));

    // Read in all index (timestamp, position pairs).
    LongList timestamps = new LongArrayList(1000);
    LongList positions = new LongArrayList(1000);
    byte[] buf = new byte[Longs.BYTES * 2];

    while (ByteStreams.read(input, buf, 0, buf.length) == buf.length) {
      timestamps.add(Bytes.toLong(buf, 0));
      positions.add(Bytes.toLong(buf, Longs.BYTES));
    }

    return Maps.immutableEntry(timestamps, positions);
  }
View Full Code Here

                   closeTo(-1, EPSILON));
    }

    @Test
    public void testVectorPredict() {
        LongList keys = new LongArrayList();
        keys.add(1);
        keys.add(2);
        keys.add(3);
        keys.add(4);
        MutableSparseVector v = MutableSparseVector.create(keys);
        pred.predict(40, v);
        assertThat(v.get(1),
                   closeTo(4.0, EPSILON));
        assertThat(v.get(2),
View Full Code Here

            typedChans = tcbld.build();
        } else {
            chans = Collections.emptyMap();
            typedChans = Collections.emptyMap();
        }
        LongList builtIds;
        DoubleList builtScores;
        if (reuse) {
            ids.trim();
            builtIds = ids;
            scores.trim();
View Full Code Here

* @author <a href="http://www.grouplens.org">GroupLens Research</a>
*/
public class CompactableLongArrayListTest {
    @Test
    public void testEmptyList() {
        LongList list = new CompactableLongArrayList();
        assertThat(list.size(), equalTo(0));
        assertThat(list.isEmpty(), equalTo(true));
    }
View Full Code Here

        assertThat(list.isEmpty(), equalTo(true));
    }

    @Test
    public void testSingleton() {
        LongList list = new CompactableLongArrayList();
        list.add(42L);
        assertThat(list.size(), equalTo(1));
        assertThat(list.isEmpty(), equalTo(false));
        assertThat(list, contains(42L));
    }
View Full Code Here

TOP

Related Classes of it.unimi.dsi.fastutil.longs.LongList

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.