Java 类gnu.trove.map.hash.TLongIntHashMap 实例源码

项目:EmbeddableSearch    文件:DigramLongSearchHistogramTest.java   
@Test
public void testAddRemoveSearchMultiResultMap3() {
    DigramLongSearchHistogram digramHistogram = new DigramLongSearchHistogram();
    long desiredResultId = 1;
    long desiredResultId2 = 2;

    digramHistogram.add("word1", "word2", desiredResultId);
    digramHistogram.add("word1", "word2", desiredResultId);
    digramHistogram.add("word1", "word3", desiredResultId2);
    digramHistogram.remove("word1", "word2", desiredResultId);

    TLongIntHashMap results = digramHistogram.getSearchResults(toSet("word1 word2"), 1);
    assertEquals(0, results.size());

    results = digramHistogram.getSearchResults(toSet("word1 word3"), 1);
    assertEquals(1, results.size()); // only 1 result returned
    assertTrue(results.contains(desiredResultId2)); // desired result key contained
    assertEquals(1, results.get(desiredResultId2)); // desired result has correct weight

}
项目:olca-modules    文件:TroveTests.java   
@Test
public void testChangeNoEntryValues() {
    //@formatter:off
    TLongIntHashMap map = new TLongIntHashMap(
            Constants.DEFAULT_CAPACITY, 
            Constants.DEFAULT_LOAD_FACTOR, 
            -1L, // no-key value 
            -1 // no entry value
    );
    //@formatter:on

    map.put(4, 2);
    Assert.assertEquals(-1L, map.getNoEntryKey());
    Assert.assertEquals(-1, map.getNoEntryValue());
    Assert.assertEquals(-1, map.get(5L));
    Assert.assertEquals(2, map.get(4L));
    Assert.assertTrue(map.contains(4));
    Assert.assertFalse(map.contains(5));
}
项目:morpheus-core    文件:IndexOfLongs.java   
/**
 * Constructor
 * @param iterable      the keys for index
 */
IndexOfLongs(Iterable<Long> iterable) {
    super(iterable);
    this.indexMap = new TLongIntHashMap(keyArray().length(), 0.75f, -1, -1);
    this.keyArray().sequential().forEachValue(v -> {
        final int index = v.index();
        final long key = v.getLong();
        final int existing = indexMap.put(key, index);
        if (existing >= 0) {
            throw new IndexException("Cannot have duplicate keys in index: " + v.getValue());
        }
    });
}
项目:morpheus-core    文件:IndexOfLongs.java   
/**
 * Constructor
 * @param iterable  the keys for index
 * @param parent    the parent index to initialize from
 */
private IndexOfLongs(Iterable<Long> iterable, IndexOfLongs parent) {
    super(iterable, parent);
    this.indexMap = new TLongIntHashMap(keyArray().length(), 0.75f, -1, -1);
    this.keyArray().sequential().forEachValue(v -> {
        final long key = v.getLong();
        final int index = parent.indexMap.get(key);
        if (index < 0) throw new IndexException("No match for key: " + v.getValue());
        final int existing = indexMap.put(key, index);
        if (existing >= 0) {
            throw new IndexException("Cannot have duplicate keys in index: " + v.getValue());
        }
    });
}
项目:morpheus-core    文件:IndexOfLongs.java   
@Override
public final Index<Long> copy() {
    try {
        final IndexOfLongs clone = (IndexOfLongs)super.copy();
        clone.indexMap = new TLongIntHashMap(indexMap);
        return clone;
    } catch (Exception ex) {
        throw new IndexException("Failed to clone index", ex);
    }
}
项目:morpheus-core    文件:IndexWithLongCoding.java   
/**
 * Constructor
 * @param iterable  the keys for this index
 * @param coding    the coding for this index
 */
IndexWithLongCoding(Iterable<T> iterable, LongCoding<T> coding) {
    super(iterable);
    this.coding = coding;
    this.indexMap = new TLongIntHashMap(keyArray().length(), 0.75f, -1L, -1);
    this.keyArray().sequential().forEachValue(v -> {
        final int index = v.index();
        final long code = v.getLong();
        final int existing = indexMap.put(code, index);
        if (existing >= 0) {
            throw new IndexException("Cannot have duplicate keys in index: " + v.getValue());
        }
    });
}
项目:morpheus-core    文件:IndexWithLongCoding.java   
/**
 * Constructor
 * @param iterable  the keys for index
 * @param coding    the coding for this index
 * @param parent    the parent index to initialize from
 */
private IndexWithLongCoding(Iterable<T> iterable, LongCoding<T> coding, IndexWithLongCoding<T> parent) {
    super(iterable, parent);
    this.coding = coding;
    this.indexMap = new TLongIntHashMap(keyArray().length(), 0.75f, -1L, -1);
    this.keyArray().sequential().forEachValue(v -> {
        final long code = v.getLong();
        final int index = parent.indexMap.get(code);
        if (index < 0) throw new IndexException("No match for key: " + v.getValue());
        final int existing = indexMap.put(code, index);
        if (existing >= 0) {
            throw new IndexException("Cannot have duplicate keys in index: " + v.getValue());
        }
    });
}
项目:morpheus-core    文件:IndexWithLongCoding.java   
@Override
@SuppressWarnings("unchecked")
public final Index<T> copy() {
    try {
        final IndexWithLongCoding<T> clone = (IndexWithLongCoding<T>)super.copy();
        clone.indexMap = new TLongIntHashMap(indexMap);
        clone.coding = coding;
        return clone;
    } catch (Exception ex) {
        throw new IndexException("Failed to clone index", ex);
    }
}
项目:morpheus-core    文件:CreateTests.java   
@Test()
public void testMapCreateTest() {
    final long t1 = System.nanoTime();
    final TObjectIntMap<String> map1 = new TObjectIntHashMap<>(5000000, 0.8f, -1);
    final long t2 = System.nanoTime();
    final TLongIntMap map2 = new TLongIntHashMap();
    final long t3 = System.nanoTime();
    System.out.println("Map1:" + ((t2-t1)/1000000d) + " Map2:" + ((t3-t2)/100000d));
}
项目:monsoon    文件:ToXdrTables.java   
private static TLongIntMap buildTimestampLookupTable(TLongList timestamps) {
    final TLongIntMap lookupTable = new TLongIntHashMap(timestamps.size(), 4, -1, -1);

    final TLongIterator iter = timestamps.iterator();
    for (int idx = 0; iter.hasNext(); ++idx)
        lookupTable.put(iter.next(), idx);

    return lookupTable;
}
项目:monsoon    文件:ToXdrTables.java   
/**
 * Build a lookup table that maps timestamps to their block index.
 *
 * @param partitions The timestamp partition table.
 * @return A lookup table, with the keys being any of the timestamps,
 * mapping to the index in the partitions list.
 */
private static TLongIntMap buildTimestampLookupTable(List<TLongList> partitions) {
    final TLongIntMap lookupTable = new TLongIntHashMap(100, 4, -1, -1);

    final ListIterator<TLongList> iter = partitions.listIterator();
    while (iter.hasNext()) {
        final int partitionIndex = iter.nextIndex();
        iter.next().forEach((ts) -> {
            lookupTable.put(ts, partitionIndex);
            return true;
        });
    }

    return lookupTable;
}
项目:EmbeddableSearch    文件:UnigramStringSearchHistogram.java   
/**
 * Get the search results by the words submitted, aggregating each word's resulting ids and ordering those resulting id's by result weight.
 * 
 * @param words The set of words to get the search results for.
 *  
 * @return A set containing the matched search results up to the specified limit
 */
public TObjectIntHashMap<String> getSearchResults(Set<String> words) {

    TLongIntHashMap longResults = super.getSearchResults(this, words);
    TObjectIntHashMap<String> stringResults = new TObjectIntHashMap<String>();

    long[] longResultKeys = longResults.keys();
    int[] longResultValues = longResults.values();

    for (int i = 0; i < longResultKeys.length; i++) {
        stringResults.put(stringLookupMap.get(((Long) longResultKeys[i]).intValue()), longResultValues[i]);
    }
    return stringResults;
}
项目:EmbeddableSearch    文件:DigramStringSearchHistogram.java   
/**
 * Get the search results by the words submitted, aggregating each word's resulting ids and ordering those resulting id's by result weight.
 * 
 * @param searchTerms The set of words to get the search results for
 * @return A set containing the matched search results up to the specified limit
 */
public TObjectIntHashMap<String> getSearchResults(Set<String> searchTerms, int weightMultiplier) {

    TLongIntHashMap longResults = super.getResultsRaw(searchTerms, weightMultiplier);
    TObjectIntHashMap<String> results = new TObjectIntHashMap<String>();

    long[] longResultKeys = longResults.keys();
    int[] longResultValues = longResults.values();

    for (int i = 0; i < longResultKeys.length; i++) {
        results.put(stringLookupMap.get((int) longResultKeys[i]), longResultValues[i]);
    }
    return results;
}
项目:EmbeddableSearch    文件:SearchHistogramUtil.java   
@SuppressWarnings("rawtypes")
public static FixedSizeSortedSet<SearchResult> resultsMapToLongSet(SearchResultType resultType, TLongIntHashMap results, int limit) {
    FixedSizeSortedSet<SearchResult> orderedResults = new FixedSizeSortedSet<SearchResult>(new SearchResultComparator(), limit);

    int count = 0;
    for (Long result : results.keys()) {
        count = results.get(result);
        orderedResults.add(new SearchResult<Long>(resultType, result, count));
    }

    return orderedResults;
}
项目:EmbeddableSearch    文件:SearchHistogramUtil.java   
public static void addResultToMap(TLongIntHashMap results, TLongIntHashMap resultsToAdd) {
    long[] resultsToAddKeys = resultsToAdd.keys();
    int[] resultsToAddValues = resultsToAdd.values();

    for (int i = 0; i < resultsToAddKeys.length; i++) {
        int count = 0;

        if (results.contains(resultsToAddKeys[i])) {
            count = results.get(resultsToAddKeys[i]);
        }
        count += resultsToAddValues[i];
        results.put(resultsToAddKeys[i], count);
    }
}
项目:EmbeddableSearch    文件:SearchHistogramUtil.java   
static void addResultToMap(TLongIntHashMap results, long result, int countIncrement) {
    int count = 0;

    if (results.contains(result)) {
        count = results.get(result);
    }
    count += countIncrement;
    results.put(result, count);

}
项目:EmbeddableSearch    文件:DigramSearchHistogram.java   
/**
 * For a given set of search terms, returns the results in order of most common occurrence.
 * A swapped order of first and second words are also taken into consideration.
 * 
 * @param searchTerms Set of potentially multiple word strings
 * @param weightMultiplier Multiplier of how much additional weight to apply to these results
 * @return A TLongIntHashMap containing all of the results and their weights
 */
protected TLongIntHashMap getResultsRaw(Set<String> searchTerms, int weightMultiplier) {
    TLongIntHashMap results = new TLongIntHashMap();

    for (String term : searchTerms) {
        String[] keywords;
        if (term.contains(" ")) {
            keywords = term.split(" ");
        } else {
            keywords = new String[] { term };
        }

        String previousWord = null;

        for (String currentWord : keywords) {
            if (previousWord != null) {
                LOGGER.debug("Looking for " + previousWord + " " + currentWord);
                UnigramSearchHistogram.getSearchResults(histogram.get(previousWord.hashCode()), results, currentWord, weightMultiplier);

                LOGGER.debug("Looking for " + currentWord + " " + previousWord);
                UnigramSearchHistogram.getSearchResults(histogram.get(currentWord.hashCode()), results, previousWord, weightMultiplier);
            }

            previousWord = currentWord;
        }
    }
    return results;
}
项目:EmbeddableSearch    文件:DigramLongSearchHistogramTest.java   
@Test
public void testAddSearchSingleResultMap() {
    DigramLongSearchHistogram digramHistogram = new DigramLongSearchHistogram();
    long desiredResultId = 1;

    digramHistogram.add("word1", "word2", desiredResultId);

    TLongIntHashMap results = digramHistogram.getSearchResults(toSet("word1 word2"), 1);

    assertEquals(1, results.size()); // only 1 result returned
    assertTrue(results.contains(desiredResultId)); // desired result key contained
    assertEquals(1, results.get(desiredResultId)); // desired result has correct weight
}
项目:EmbeddableSearch    文件:DigramLongSearchHistogramTest.java   
@Test
public void testAddSearchSingleResultMapWeightMultiplier() {
    DigramLongSearchHistogram digramHistogram = new DigramLongSearchHistogram();
    long desiredResultId = 1;

    digramHistogram.add("word1", "word2", desiredResultId);

    TLongIntHashMap results = digramHistogram.getSearchResults(toSet("word1 word2"), 10);

    assertEquals(1, results.size()); // only 1 result returned
    assertTrue(results.contains(desiredResultId)); // desired result key contained
    assertEquals(10, results.get(desiredResultId)); // desired result has correct weight
}
项目:EmbeddableSearch    文件:DigramLongSearchHistogramTest.java   
@Test
public void testAddSearchReversedOrderSingleResultMap() {
    DigramLongSearchHistogram digramHistogram = new DigramLongSearchHistogram();
    long desiredResultId = 1;

    digramHistogram.add("word1", "word2", desiredResultId);

    TLongIntHashMap results = digramHistogram.getSearchResults(toSet("word2 word1"), 1);

    assertEquals(1, results.size()); // only 1 result returned
    assertTrue(results.contains(desiredResultId)); // desired result key contained
    assertEquals(1, results.get(desiredResultId)); // desired result has correct weight
}
项目:EmbeddableSearch    文件:DigramLongSearchHistogramTest.java   
@Test
public void testAddRemoveSearchSingleResultMap1() {
    DigramLongSearchHistogram digramHistogram = new DigramLongSearchHistogram();
    long desiredResultId = 1;

    digramHistogram.add("word1", "word2", desiredResultId);
    digramHistogram.remove("word1", "word2", desiredResultId);

    TLongIntHashMap results = digramHistogram.getSearchResults(toSet("word1 word2"), 1);

    assertEquals(0, results.size());
}
项目:EmbeddableSearch    文件:DigramLongSearchHistogramTest.java   
@Test
public void testAddRemoveSearchSingleResultMap2() {
    DigramLongSearchHistogram digramHistogram = new DigramLongSearchHistogram();
    long desiredResultId = 1;

    digramHistogram.add("word1", "word2", desiredResultId);
    digramHistogram.add("word3", "word4", desiredResultId); // creates another single result map for "word3"
    digramHistogram.remove("word1", "word2", desiredResultId);

    TLongIntHashMap results = digramHistogram.getSearchResults(toSet("word1 word2"), 1);

    assertEquals(0, results.size());
}
项目:EmbeddableSearch    文件:DigramLongSearchHistogramTest.java   
@Test
public void testAddSearchMultiResultMap1() {
    DigramLongSearchHistogram digramHistogram = new DigramLongSearchHistogram();
    long desiredResultId = 1;

    digramHistogram.add("word1", "word2", desiredResultId);
    digramHistogram.add("word1", "word2", desiredResultId);

    TLongIntHashMap results = digramHistogram.getSearchResults(toSet("word1 word2"), 1);

    assertEquals(1, results.size()); // only 1 result returned
    assertTrue(results.contains(desiredResultId)); // desired result key contained
    assertEquals(2, results.get(desiredResultId)); // desired result has correct weight
}
项目:EmbeddableSearch    文件:DigramLongSearchHistogramTest.java   
@Test
public void testAddSearchMultiResultMap2() {
    DigramLongSearchHistogram digramHistogram = new DigramLongSearchHistogram();
    long desiredResultId = 1;

    digramHistogram.add("word1", "word2", desiredResultId);
    digramHistogram.add("word1", "word3", desiredResultId);

    TLongIntHashMap results = digramHistogram.getSearchResults(toSet("word1 word2"), 1);

    assertEquals(1, results.size()); // only 1 result returned
    assertTrue(results.contains(desiredResultId)); // desired result key contained
    assertEquals(1, results.get(desiredResultId)); // desired result has correct weight
}
项目:EmbeddableSearch    文件:DigramLongSearchHistogramTest.java   
@Test
public void testAddSearchReversedOrderMultiResultMap1() {
    DigramLongSearchHistogram digramHistogram = new DigramLongSearchHistogram();
    long desiredResultId = 1;

    digramHistogram.add("word1", "word2", desiredResultId);
    digramHistogram.add("word1", "word2", desiredResultId);

    TLongIntHashMap results = digramHistogram.getSearchResults(toSet("word2 word1"), 1);

    assertEquals(1, results.size()); // only 1 result returned
    assertTrue(results.contains(desiredResultId)); // desired result key contained
    assertEquals(2, results.get(desiredResultId)); // desired result has correct weight
}
项目:EmbeddableSearch    文件:DigramLongSearchHistogramTest.java   
@Test
public void testAddSearchReversedOrderMultiResultMap2() {
    DigramLongSearchHistogram digramHistogram = new DigramLongSearchHistogram();
    long desiredResultId = 1;

    digramHistogram.add("word1", "word2", desiredResultId);
    digramHistogram.add("word2", "word1", desiredResultId);

    TLongIntHashMap results = digramHistogram.getSearchResults(toSet("word2 word1"), 1);

    assertEquals(1, results.size()); // only 1 result returned
    assertTrue(results.contains(desiredResultId)); // desired result key contained
    assertEquals(2, results.get(desiredResultId)); // desired result has correct weight
}
项目:EmbeddableSearch    文件:DigramLongSearchHistogramTest.java   
@Test
public void testAddRemoveSearchMultiResultMap1() {
    DigramLongSearchHistogram digramHistogram = new DigramLongSearchHistogram();
    long desiredResultId = 1;

    digramHistogram.add("word1", "word2", desiredResultId);
    digramHistogram.add("word1", "word2", desiredResultId);
    digramHistogram.remove("word1", "word2", desiredResultId);

    TLongIntHashMap results = digramHistogram.getSearchResults(toSet("word1 word2"), 1);

    assertEquals(0, results.size()); // only 1 result returned
}
项目:EmbeddableSearch    文件:DigramLongSearchHistogramTest.java   
@Test
public void testAddRemoveSearchMultiResultMap2() {
    DigramLongSearchHistogram digramHistogram = new DigramLongSearchHistogram();
    long desiredResultId = 1;

    digramHistogram.add("word1", "word2", desiredResultId);
    digramHistogram.add("word1", "word2", desiredResultId);
    digramHistogram.remove("word1", "word2", 2);

    TLongIntHashMap results = digramHistogram.getSearchResults(toSet("word1 word2"), 1);

    assertEquals(1, results.size()); // only 1 result returned
    assertTrue(results.contains(desiredResultId)); // desired result key contained
    assertEquals(2, results.get(desiredResultId)); // desired result has correct weight
}
项目:SRLParser    文件:Alphabet.java   
public Alphabet(Alphabet a)
{
    numEntries = a.numEntries;
    map = new TLongIntHashMap(numEntries);      
    for (TLongIntIterator iter = a.map.iterator(); iter.hasNext();) {
        iter.advance();
        map.put(iter.key(), iter.value());
    }
}
项目:offheapstore-benchmark    文件:ChronicleStore.java   
public ChronicleStore() throws IOException {
    file = FileUtils.createTempFile();

    LOGGER.info("Using " + file.getAbsolutePath());

    chronicle = new IndexedChronicle(file.getAbsolutePath());
    posMap = new TObjectLongHashMap<Serializable>(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, NO_ENTRY);
    posSizeMap = new TLongIntHashMap(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, NO_ENTRY, NO_ENTRY);
    freePosSizeMap = new TIntObjectHashMap<TLongList>(Constants.DEFAULT_CAPACITY, Constants.DEFAULT_LOAD_FACTOR, NO_ENTRY);
    freePosMaxSize = 0;

    appender = chronicle.createAppender();
    randomAccessor = chronicle.createExcerpt();
}
项目:it.cnr.isti.vir    文件:L_HammingLongs.java   
public L_HammingLongs(File file) throws Exception {

DataInputStream in = new DataInputStream(new BufferedInputStream(
        new FileInputStream(file)));

    File bFile = new File(file.getAbsolutePath() + ".b");       
bucketsRAF = new RandomAccessFile(bFile, "r");      
fileChannel = bucketsRAF.getChannel();

    h = in.readInt();
    nh = 1 << h;
    g = new G_HammingLongs(in);

    int nNotNulls = in.readInt();

    //bSize = new int[nh];
    //bucketOffset = new long[nh];
    bSize = new TLongIntHashMap();;
    bucketOffset = new TLongLongHashMap();
    long offsetAcc = 0;

    for ( int i=0; i<nNotNulls; i++ ) {
    int ib = in.readInt();
        int csize =  in.readInt();

        //bSize[ib] = csize;
        //bucketOffset[ib] = offsetAcc;

        bSize.put(ib, csize);
    bucketOffset.put(ib, offsetAcc);
    if (csize != 0) {
        offsetAcc += csize * Integer.BYTES; 
    }
}

in.close();

  }
项目:ProjectAres    文件:BlockMaterialMap.java   
public BlockMaterialMap(int capacity) {
    this(new TLongIntHashMap(capacity, Constants.DEFAULT_LOAD_FACTOR, NO_KEY, NO_VALUE));
}
项目:morpheus-core    文件:IndexOfLongs.java   
/**
 * Constructor
 * @param initialSize   the initial size for this index
 */
IndexOfLongs(int initialSize) {
    super(Array.of(Long.class, initialSize));
    this.indexMap = new TLongIntHashMap(initialSize, 0.75f, -1, -1);
}
项目:bigcat    文件:H5IntLabelMultisetArrayLoader.java   
@Override
    public VolatileLabelMultisetArray loadArrayLevel0(
            final int[] dimensions,
            final long[] min ) throws InterruptedException
    {
        int[] data = null;

        final MDIntArray block = reader.readMDArrayBlockWithOffset(
                dataset,
                new int[]{ dimensions[ 2 ], dimensions[ 1 ], dimensions[ 0 ] },
                new long[]{ min[ 2 ], min[ 1 ], min[ 0 ] } );

        data = block.getAsFlatArray();

        if ( data == null )
        {
            System.out.println(
                    "H5 short label multiset array loader failed loading min = " +
                    Arrays.toString( min ) +
                    ", dimensions = " +
                    Arrays.toString( dimensions ) );

            data = new int[ dimensions[ 0 ] * dimensions[ 1 ] * dimensions[ 2 ] ];
        }

        final int[] offsets = new int[ dimensions[ 2 ] * dimensions[ 1 ] * dimensions[ 0 ] ];
        final LongMappedAccessData listData = LongMappedAccessData.factory.createStorage( 32 );
        final LabelMultisetEntryList list = new LabelMultisetEntryList( listData, 0 );
        final LabelMultisetEntry entry = new LabelMultisetEntry( 0, 1 );
        int nextListOffset = 0;
        final TLongIntHashMap idOffsetHash = new TLongIntHashMap(
                Constants.DEFAULT_CAPACITY,
                Constants.DEFAULT_LOAD_FACTOR,
                -1,
                -1);
A:      for ( int i = 0; i < data.length; ++i )
        {
            final long id = data[ i ] & 0xffffffffL;

            final int offset = idOffsetHash.get( id );
            if ( offset == idOffsetHash.getNoEntryValue() )
            {
                list.createListAt( listData, nextListOffset );
                entry.setId( id );
                list.add( entry );
                offsets[ i ] = nextListOffset;
                idOffsetHash.put( id, nextListOffset );
                nextListOffset += list.getSizeInBytes();
            }
            else
            {
                offsets[ i ] = offset;
                continue A;
            }
        }
//      System.out.println( listData.size() );

        return new VolatileLabelMultisetArray( offsets, listData, true );
    }
项目:bigcat    文件:H5ShortLabelMultisetArrayLoader.java   
@Override
    public VolatileLabelMultisetArray loadArrayLevel0(
            final int[] dimensions,
            final long[] min ) throws InterruptedException
    {
        short[] data = null;

        final MDShortArray block = reader.readMDArrayBlockWithOffset(
                dataset,
                new int[]{ dimensions[ 2 ], dimensions[ 1 ], dimensions[ 0 ] },
                new long[]{ min[ 2 ], min[ 1 ], min[ 0 ] } );

        data = block.getAsFlatArray();

        if ( data == null )
        {
            System.out.println(
                    "H5 short label multiset array loader failed loading min = " +
                    Arrays.toString( min ) +
                    ", dimensions = " +
                    Arrays.toString( dimensions ) );

            data = new short[ dimensions[ 0 ] * dimensions[ 1 ] * dimensions[ 2 ] ];
        }

        final int[] offsets = new int[ dimensions[ 2 ] * dimensions[ 1 ] * dimensions[ 0 ] ];
        final LongMappedAccessData listData = LongMappedAccessData.factory.createStorage( 32 );
        final LabelMultisetEntryList list = new LabelMultisetEntryList( listData, 0 );
        final LabelMultisetEntry entry = new LabelMultisetEntry( 0, 1 );
        int nextListOffset = 0;
        final TLongIntHashMap idOffsetHash = new TLongIntHashMap(
                Constants.DEFAULT_CAPACITY,
                Constants.DEFAULT_LOAD_FACTOR,
                -1,
                -1);
A:      for ( int i = 0; i < data.length; ++i )
        {
            final long id = data[ i ] & 0xffffL;

//          does the list [id x 1] already exist?
            final int offset = idOffsetHash.get( id );
            if ( offset == idOffsetHash.getNoEntryValue() )
            {
                list.createListAt( listData, nextListOffset );
                entry.setId( id );
                list.add( entry );
                offsets[ i ] = nextListOffset;
                idOffsetHash.put( id, nextListOffset );
                nextListOffset += list.getSizeInBytes();
            }
            else
            {
                offsets[ i ] = offset;
                continue A;
            }
        }
//      System.out.println( listData.size() );

        return new VolatileLabelMultisetArray( offsets, listData, true );
    }
项目:bigcat    文件:H5FloatLabelMultisetArrayLoader.java   
@Override
    public VolatileLabelMultisetArray loadArrayLevel0(
            final int[] dimensions,
            final long[] min ) throws InterruptedException
    {
        float[] data = null;

        final MDFloatArray block = reader.readMDArrayBlockWithOffset(
                dataset,
                new int[]{ dimensions[ 2 ], dimensions[ 1 ], dimensions[ 0 ] },
                new long[]{ min[ 2 ], min[ 1 ], min[ 0 ] } );

        data = block.getAsFlatArray();

        if ( data == null )
        {
            System.out.println(
                    "H5 short label multiset array loader failed loading min = " +
                    Arrays.toString( min ) +
                    ", dimensions = " +
                    Arrays.toString( dimensions ) );

            data = new float[ dimensions[ 0 ] * dimensions[ 1 ] * dimensions[ 2 ] ];
        }

        final int[] offsets = new int[ dimensions[ 2 ] * dimensions[ 1 ] * dimensions[ 0 ] ];
        final LongMappedAccessData listData = LongMappedAccessData.factory.createStorage( 32 );
        final LabelMultisetEntryList list = new LabelMultisetEntryList( listData, 0 );
        final LabelMultisetEntry entry = new LabelMultisetEntry( 0, 1 );
        int nextListOffset = 0;
        final TLongIntHashMap idOffsetHash = new TLongIntHashMap(
                Constants.DEFAULT_CAPACITY,
                Constants.DEFAULT_LOAD_FACTOR,
                -1,
                -1);
A:      for ( int i = 0; i < data.length; ++i )
        {
            final long id = Float.floatToIntBits( data[ i ] ) & 0xffffffffL;

            final int offset = idOffsetHash.get( id );
            if ( offset == idOffsetHash.getNoEntryValue() )
            {
                list.createListAt( listData, nextListOffset );
                entry.setId( id );
                list.add( entry );
                offsets[ i ] = nextListOffset;
                idOffsetHash.put( id, nextListOffset );
                nextListOffset += list.getSizeInBytes();
            }
            else
            {
                offsets[ i ] = offset;
                continue A;
            }
        }
//      System.out.println( listData.size() );

        return new VolatileLabelMultisetArray( offsets, listData, true );
    }
项目:bigcat    文件:H5LongLabelMultisetArrayLoader.java   
@Override
    public VolatileLabelMultisetArray loadArrayLevel0(
            final int[] dimensions,
            final long[] min ) throws InterruptedException
    {
        long[] data = null;

        final MDLongArray block = reader.readMDArrayBlockWithOffset(
                dataset,
                new int[]{ dimensions[ 2 ], dimensions[ 1 ], dimensions[ 0 ] },
                new long[]{ min[ 2 ], min[ 1 ], min[ 0 ] } );

        data = block.getAsFlatArray();

        if ( data == null )
        {
            System.out.println(
                    "H5 long label multiset array loader failed loading min = " +
                    Arrays.toString( min ) +
                    ", dimensions = " +
                    Arrays.toString( dimensions ) );

            data = new long[ dimensions[ 0 ] * dimensions[ 1 ] * dimensions[ 2 ] ];
        }

        final int[] offsets = new int[ dimensions[ 2 ] * dimensions[ 1 ] * dimensions[ 0 ] ];
        final LongMappedAccessData listData = LongMappedAccessData.factory.createStorage( 32 );
        final LabelMultisetEntryList list = new LabelMultisetEntryList( listData, 0 );
        final LabelMultisetEntry entry = new LabelMultisetEntry( 0, 1 );
        int nextListOffset = 0;
        final TLongIntHashMap idOffsetHash = new TLongIntHashMap(
                Constants.DEFAULT_CAPACITY,
                Constants.DEFAULT_LOAD_FACTOR,
                -1,
                -1 );
A:      for ( int i = 0; i < data.length; ++i )
        {
            final long id = data[ i ];

//          does the list [id x 1] already exist?
            final int offset = idOffsetHash.get( id );
            if ( offset == idOffsetHash.getNoEntryValue() )
            {
                list.createListAt( listData, nextListOffset );
                entry.setId( id );
                list.add( entry );
                offsets[ i ] = nextListOffset;
                idOffsetHash.put( id, nextListOffset );
                nextListOffset += list.getSizeInBytes();
            }
            else
            {
                offsets[ i ] = offset;
                continue A;
            }
        }
//      System.out.println( listData.size() );

        return new VolatileLabelMultisetArray( offsets, listData, nextListOffset, true );
    }
项目:EmbeddableSearch    文件:InMemorySearchEngine.java   
@SuppressWarnings("rawtypes")
@Override

public Set<SearchResult> search(String searchTerm, int limit) {
    searchCount++;
    long t1 = System.currentTimeMillis();

    boolean hasTrailingSpace = searchTerm.endsWith(" ");

    String scrubbedSearchTerm = textScrubber.scrubText(searchTerm);
    String[] words = splitter.splitContent(scrubbedSearchTerm);
    List<String> keywords = keywordScrubber.scrubKeywords(words);

    timeForScrubbing += System.currentTimeMillis() - t1;
    t1 = System.currentTimeMillis();

    Set<String> uniqCompletions = autocomplete.getCompletions(keywords, true, hasTrailingSpace, limit * 2);
    for (String s : uniqCompletions) {
    }

    timeForCompletions += System.currentTimeMillis() - t1;
    t1 = System.currentTimeMillis();

    TLongIntHashMap longResults = new TLongIntHashMap();
    TObjectIntHashMap<String> stringResults = new TObjectIntHashMap<String>();

    if (keywords.size() > 1) {
        longResults = digramLongSearchHistogram.getSearchResults(uniqCompletions, 10);
        stringResults = digramStringSearchHistogram.getSearchResults(uniqCompletions, 10);
    }

    SearchHistogramUtil.addResultToMap(longResults, UnigramLongSearchHistogram.getSearchResults(unigramLongSearchHistogram, uniqCompletions));
    SearchHistogramUtil.addResultToMap(stringResults, unigramStringSearchHistogram.getSearchResults(uniqCompletions));

    FixedSizeSortedSet<SearchResult> results = SearchHistogramUtil.resultsMapToLongSet(SearchResultType.LONG, longResults, limit);
    FixedSizeSortedSet<SearchResult> resultsString = SearchHistogramUtil.resultsMapToStringSet(SearchResultType.STRING, stringResults, limit);

    LOGGER.debug("Long results: " + results.size());
    LOGGER.debug("String results: " + resultsString.size());

    for (SearchResult searchResult : resultsString) { // combine and sort the results from each type
        results.add(searchResult);
    }

    timeForSearchResults += System.currentTimeMillis() - t1;
    return results;
}
项目:SRLParser    文件:Alphabet.java   
public Alphabet (int capacity)
  {
    this.map = new TLongIntHashMap(capacity);
numEntries = 0;
  }
项目:SRLParser    文件:Alphabet.java   
private void readObject (ObjectInputStream in) throws IOException, ClassNotFoundException {
int version = in.readInt ();
numEntries = in.readInt();
map = (TLongIntHashMap)in.readObject();
growthStopped = in.readBoolean();
  }