Java源码示例:gnu.trove.map.TIntIntMap
示例1
public static Map<Integer, Integer> convertToJava(TIntIntMap map) {
Map<Integer, Integer> javaMap = new HashMap<>();
for (int key : map.keys()) {
javaMap.put(key, map.get(key));
}
return javaMap;
}
示例2
private static int[] getPermutationArray(int[] l2, int[] l1) {
final int count = l1.length;
TIntIntMap map = new TIntIntHashMap(count);
for (int i = 0; i < count; ++i) {
map.put(l1[i], i);
}
int[] result = new int[count];
for (int i = 0; i < count; ++i) {
result[i] = map.get(l2[i]);
}
return result;
}
示例3
private static mt_32bit encode32Bit(TIntIntMap t_32bit, int timestampsSize) {
LOG.log(Level.FINEST, "encoding {0}", TDecorators.wrap(t_32bit));
int[] values = new int[timestampsSize];
int values_len = 0;
for (int i = 0; i < values.length; ++i) {
if (t_32bit.containsKey(i))
values[values_len++] = t_32bit.get(i);
}
mt_32bit result = new mt_32bit();
result.presence = createPresenceBitset(t_32bit.keySet(), timestampsSize);
result.values = Arrays.copyOf(values, values_len);
return result;
}
示例4
private static mt_str encodeStr(TIntIntMap t_str, int timestampsSize) {
LOG.log(Level.FINEST, "encoding {0}", TDecorators.wrap(t_str));
int[] values = new int[timestampsSize];
int values_len = 0;
for (int i = 0; i < values.length; ++i) {
if (t_str.containsKey(i))
values[values_len++] = t_str.get(i);
}
mt_str result = new mt_str();
result.presence = createPresenceBitset(t_str.keySet(), timestampsSize);
result.values = Arrays.copyOf(values, values_len);
return result;
}
示例5
@Override
public int test() {
final TIntIntMap m_map = new TIntIntHashMap( m_keys.length, m_fillFactor );
for ( int i = 0; i < m_keys.length; ++i )
m_map.put( m_keys[ i ], m_keys[ i ] );
for ( int i = 0; i < m_keys.length; ++i )
m_map.put( m_keys[ i ], m_keys[ i ] );
return m_map.size();
}
示例6
@Override
public int test() {
final TIntIntMap m_map = new TIntIntHashMap( m_keys.length / 2 + 1, m_fillFactor );
int add = 0, remove = 0;
while ( add < m_keys.length )
{
m_map.put( m_keys[ add ], m_keys[ add ] );
++add;
m_map.put( m_keys[ add ], m_keys[ add ] );
++add;
m_map.remove( m_keys[ remove++ ] );
}
return m_map.size();
}
示例7
private MaterialCounter(TIntIntMap counts) {
this.counts = counts;
}
示例8
@Override
public TIntIntMap getBlockedConnectionsMap() {
return new TIntIntHashMap(blockedConnectionsMap);
}
示例9
public TIntIntMap getTransientWordExpansions() {
return transientWordExpansions_;
}
示例10
@Override public double calcSimilarity(Mention mention, Context context, Entity entity, EntitiesContext entitiesContext)
throws EntityLinkingDataAccessException {
if (!(entitiesContext instanceof LanguageModelContext)) {
logger.warn("LanguageModelMentionEntitySimilarityMeasure#calcSimilarity() "
+ "was invoked with an EntitiesContext that's not a LanguageModelContext => " + "returning 0.0 as similarity");
return 0d;
}
LanguageModelContext languageModelContext = (LanguageModelContext) entitiesContext;
if (originalInputText == null) {
logger.debug("Calculating similarity, original input text is null.");
originalInputText = new InputTextWrapper(context, unitType, removeStopwords);
}
if (languageModelContext.shouldIgnoreMention(unitType)) originalInputText.mentionToIgnore(mention);
KLDivergenceCalculator klDivergenceCalculator = new KLDivergenceCalculator(normalized);
TIntIntMap unitCountsForEntity = languageModelContext.getUnitCountsForEntity(entity, unitType);
UnitMeasureTracer mt = null;
if (isTracing) mt = new UnitMeasureTracer(getIdentifier(), 0.0, unitCountsForEntity.size());
int entityUnitsSum = 0;
for (int unitCount : unitCountsForEntity.values()) {
entityUnitsSum += unitCount;
}
int unitGlobalCount, unitEntityCount;
for (int unit : originalInputText.getUnits()) {
if (unit == 0) continue;
unitGlobalCount = languageModelContext.getUnitCount(unit, unitType);
unitEntityCount = unitCountsForEntity.get(unit);
// this check makes sure that the unit exist for this unitType
if (unitGlobalCount == 0) continue;
double summand = -klDivergenceCalculator
.addSummand(originalInputText.getUnitCount(unit), originalInputText.getSize(), unitEntityCount, entityUnitsSum,
languageModelContext.getUnitCount(unit, unitType), languageModelContext.getCollectionSize(),
languageModelContext.getSmoothingParameter(unitType));
if (mt != null) mt.addUnitTraceInfo(unit, summand, unitEntityCount != 0);
}
if (mt != null) {
mt.setScore(-klDivergenceCalculator.getKLDivergence());
tracer.addMeasureForMentionEntity(mention, entity.getId(), mt);
}
return -klDivergenceCalculator.getKLDivergence();
}
示例11
public TIntIntMap getUnitCountsForEntity(Entity entity, UnitType unitType) {
TIntObjectHashMap<TIntIntHashMap> curEntityUnitCounts = entityUnitCounts.get(unitType.ordinal());
if (curEntityUnitCounts == null) return new TIntIntHashMap();
TIntIntHashMap curUnitCounts = curEntityUnitCounts.get(entity.getId());
return curUnitCounts != null ? curUnitCounts : new TIntIntHashMap();
}
示例12
public TIntIntMap getOpCounts() {
return opCounts;
}
示例13
public static void rollUp(TIntIntMap dest, TIntIntMap src) {
for (int key : src.keys()) {
int value = src.get(key);
dest.adjustOrPutValue(key, value, value);
}
}
示例14
public void buildPLIs() {
long time = System.currentTimeMillis();
final int COLUMN_COUNT = parsedColumns.size();
final int ROW_COUNT = getLineCount();
List<Integer> tIDs = new TupleIDProvider(ROW_COUNT).gettIDs(); // to save integers storage
int[][] inputs = getInts();
for (int col = 0; col < COLUMN_COUNT; ++col) {
TIntSet distincts = new TIntHashSet();
for (int line = 0; line < ROW_COUNT; ++line) {
distincts.add(inputs[line][col]);
}
int[] distinctsArray = distincts.toArray();
// need to sort for doubles and integers
if (!(parsedColumns.get(col).getType() == String.class)) {
Arrays.sort(distinctsArray);// ascending is the default
}
TIntIntMap translator = new TIntIntHashMap();
for (int position = 0; position < distinctsArray.length; position++) {
translator.put(distinctsArray[position], position);
}
List<Set<Integer>> setPlis = new ArrayList<>();
for (int i = 0; i < distinctsArray.length; i++) {
setPlis.add(new TreeSet<Integer>());
}
for (int line = 0; line < ROW_COUNT; ++line) {
Integer tid = tIDs.get(line);
setPlis.get(translator.get(inputs[line][col])).add(tid);
}
int values[] = new int[ROW_COUNT];
for (int line = 0; line < ROW_COUNT; ++line) {
values[line] = inputs[line][col];
}
PLI pli;
if (!(parsedColumns.get(col).getType() == String.class)) {
pli = new PLI(setPlis, ROW_COUNT, true, values);
} else {
pli = new PLI(setPlis, ROW_COUNT, false, values);
}
parsedColumns.get(col).setPLI(pli);
}
log.info("Time to build plis: " + (System.currentTimeMillis() - time));
}
示例15
private MaterialCounter(TIntIntMap counts) {
this.counts = counts;
}
示例16
private List<Comparison> performJoin() {
final List<Comparison> executedComparisons = new ArrayList<>();
final TIntObjectMap<ListItemPPJ> index = new TIntObjectHashMap<>();
for (int k = 0; k < noOfEntities; k++) {
final TIntList record = records[k];
int minLength = minPossibleLength(record.size());
int probeLength = probeLength(record.size());
int indexLength = indexLength(record.size());
final int[] requireOverlaps = new int[record.size() + 1];
for (int l = minLength; l <= record.size(); l++) {
requireOverlaps[l] = requireOverlap(record.size(), l);
}
final TIntIntMap occurances = new TIntIntHashMap();
for (int t = 0; t < probeLength; t++) {
int token = record.get(t);
ListItemPPJ item = index.get(token);
if (item == null) {
item = new ListItemPPJ();
index.put(token, item);
}
int pos = item.getPos();
final List<IntPair> ids = item.getIds();
int noOfIds = ids.size();
while (pos < noOfIds && records[ids.get(pos).getKey()].size() < minLength) {
pos++;
}
for (int p = pos; p < noOfIds; p++) {
int candId = ids.get(p).getKey();
int oldValue = occurances.get(candId);
occurances.put(candId, (oldValue + 1));
}
if (t < indexLength) {
ids.add(new IntPair(k, t));
}
}
for (int cand : occurances.keys()) {
if (k == cand) {
continue;
}
if (isCleanCleanER) {
if (originalId[k] < datasetDelimiter && originalId[cand] < datasetDelimiter) { // both belong to dataset 1
continue;
}
if (datasetDelimiter <= originalId[k] && datasetDelimiter <= originalId[cand]) { // both belong to dataset 2
continue;
}
}
int noOfCandidates = records[cand].size();
int newindexLength = indexLength(noOfCandidates);
if (records[cand].get(newindexLength - 1) < records[k].get(probeLength - 1)) {
if (occurances.get(cand) + noOfCandidates - newindexLength < requireOverlaps[noOfCandidates]) {
continue;
}
} else {
if (occurances.get(cand) + records[k].size() - probeLength < requireOverlaps[noOfCandidates]) {
continue;
}
}
int realOverlap = getOverlap(k, cand, requireOverlaps[noOfCandidates]);
if (realOverlap != -1) {
float jaccardSim = calcSimilarity(records[k].size(), noOfCandidates, realOverlap);
if (jaccardSim >= threshold) {
final Comparison currentComp = getComparison(originalId[k], originalId[cand]);
currentComp.setUtilityMeasure(jaccardSim); // is this correct?
executedComparisons.add(currentComp);
}
}
}
}
return executedComparisons;
}
示例17
/** See {@link gnu.trove.map.hash.TIntIntHashMap#putAll(TIntIntMap)} */
public void putAll(TIntIntMap map) {
delegate.putAll(map);
}
示例18
TIntIntMap getBlockedConnectionsMap();