本文整理汇总了Java中gnu.trove.map.hash.TLongIntHashMap类的典型用法代码示例。如果您正苦于以下问题:Java TLongIntHashMap类的具体用法?Java TLongIntHashMap怎么用?Java TLongIntHashMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TLongIntHashMap类属于gnu.trove.map.hash包,在下文中一共展示了TLongIntHashMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAddRemoveSearchMultiResultMap3
import gnu.trove.map.hash.TLongIntHashMap; //导入依赖的package包/类
@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
}
示例2: testChangeNoEntryValues
import gnu.trove.map.hash.TLongIntHashMap; //导入依赖的package包/类
@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));
}
示例3: IndexOfLongs
import gnu.trove.map.hash.TLongIntHashMap; //导入依赖的package包/类
/**
* 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());
}
});
}
示例4: copy
import gnu.trove.map.hash.TLongIntHashMap; //导入依赖的package包/类
@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);
}
}
示例5: IndexWithLongCoding
import gnu.trove.map.hash.TLongIntHashMap; //导入依赖的package包/类
/**
* 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());
}
});
}
示例6: copy
import gnu.trove.map.hash.TLongIntHashMap; //导入依赖的package包/类
@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);
}
}
示例7: testMapCreateTest
import gnu.trove.map.hash.TLongIntHashMap; //导入依赖的package包/类
@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));
}
示例8: buildTimestampLookupTable
import gnu.trove.map.hash.TLongIntHashMap; //导入依赖的package包/类
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;
}
示例9: getSearchResults
import gnu.trove.map.hash.TLongIntHashMap; //导入依赖的package包/类
/**
* 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;
}
示例10: getSearchResults
import gnu.trove.map.hash.TLongIntHashMap; //导入依赖的package包/类
/**
* 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;
}
示例11: resultsMapToLongSet
import gnu.trove.map.hash.TLongIntHashMap; //导入依赖的package包/类
@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;
}
示例12: addResultToMap
import gnu.trove.map.hash.TLongIntHashMap; //导入依赖的package包/类
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);
}
}
示例13: getResultsRaw
import gnu.trove.map.hash.TLongIntHashMap; //导入依赖的package包/类
/**
* 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;
}
示例14: testAddSearchSingleResultMap
import gnu.trove.map.hash.TLongIntHashMap; //导入依赖的package包/类
@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
}
示例15: testAddSearchSingleResultMapWeightMultiplier
import gnu.trove.map.hash.TLongIntHashMap; //导入依赖的package包/类
@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
}