Java Code Examples for it.unimi.dsi.fastutil.objects.Object2IntMap#Entry
The following examples show how to use
it.unimi.dsi.fastutil.objects.Object2IntMap#Entry .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LanguageDetector.java From jstarcraft-nlp with Apache License 2.0 | 6 votes |
/** * 获取得分 * * @param tuples * @param trie * @return */ private double getScore(Object2IntMap<CharSequence> tuples, ITrie<Integer> trie) { double score = 0D; Integer difference; for (Object2IntMap.Entry<CharSequence> tuple : tuples.object2IntEntrySet()) { difference = trie.get(tuple.getKey().toString()); if (difference == null) { difference = DEFAULT_DIFFERENCE; } else { difference = tuple.getIntValue() - difference - 1; if (difference < 0) { difference = -difference; } } score += difference; } return score; }
Example 2
Source File: DioriteRandomUtils.java From Diorite with MIT License | 6 votes |
@Nullable public static <T> T getWeightedRandom(Random random, Object2IntMap<T> choices) { long i = 0; IntCollection ints = choices.values(); for (IntIterator iterator = ints.iterator(); iterator.hasNext(); ) { int x = iterator.nextInt(); i += x; } i = getRandomLong(random, 0, i); for (Object2IntMap.Entry<T> entry : choices.object2IntEntrySet()) { i -= entry.getIntValue(); if (i < 0) { return entry.getKey(); } } return null; }
Example 3
Source File: ASTAssociation.java From symja_android_library with GNU General Public License v3.0 | 6 votes |
/** {@inheritDoc} */ @Override public IExpr evaluate(EvalEngine engine) { if (isEvalFlagOff(IAST.BUILT_IN_EVALED)) { addEvalFlags(IAST.BUILT_IN_EVALED); ASTAssociation result = null; for (Object2IntMap.Entry<IExpr> element : map.object2IntEntrySet()) { int value = element.getIntValue(); if (value > 0) { // for Rules eval rhs / for RuleDelayed don't IExpr temp = engine.evaluateNull(get(value)); if (temp.isPresent()) { if (result == null) { result = copy(); } result.set(value, temp); } } } if (result != null) { return result; } } return F.NIL; }
Example 4
Source File: ASTAssociation.java From symja_android_library with GNU General Public License v3.0 | 6 votes |
@Override public IExpr remove(int location) { normalCache = null; IExpr result = super.remove(location); for (Object2IntMap.Entry<IExpr> element : map.object2IntEntrySet()) { int value = element.getIntValue(); int indx = value; if (indx < 0) { indx *= -1; } if (indx > location) { element.setValue(value > 0 ? --value : ++value); } else if (indx == location) { map.remove(element.getKey(), value); } } return result; }
Example 5
Source File: TableReader.java From fastjgame with Apache License 2.0 | 5 votes |
/** * 读取内容行 * * @param colNameRow 属性列信息 * @param rowIndex 行索引 * @param row 行内容 * @return 内容行 */ private TableRow readContentRow(ColNameRow colNameRow, int rowIndex, T row) { // 使用LinkedHashMap以保持读入顺序 Map<String, String> colName2Value = new LinkedHashMap<>(); // 读取所有属性 for (Object2IntMap.Entry<String> entry : colNameRow.getColName2Index().object2IntEntrySet()) { String colName = entry.getKey(); int colIndex = entry.getIntValue(); String value = getNullableCell(row, colIndex); colName2Value.put(colName, null == value ? "" : value); } return new TableRow(rowIndex, colName2Value); }
Example 6
Source File: CounterSet.java From WikipediaEntities with GNU Affero General Public License v3.0 | 5 votes |
/** * Get a descending list of counted items. * * @return List of items. */ public static <O> List<Entry<O>> descending(Object2IntOpenHashMap<O> counters) { ArrayList<Entry<O>> copy = new ArrayList<>(counters.size()); for(Iterator<Object2IntMap.Entry<O>> iter = counters.object2IntEntrySet().fastIterator(); iter.hasNext();) { // Note: fast iterator will recycle this object! Object2IntMap.Entry<O> entry = iter.next(); copy.add(new Entry<O>(entry.getKey(), entry.getIntValue())); } Collections.sort(copy); return copy; }
Example 7
Source File: CounterSet.java From WikipediaEntities with GNU Affero General Public License v3.0 | 5 votes |
/** * Merge second counter set. * * @param other Other set of counters. */ public static <O> void update(Object2IntOpenHashMap<O> first, Object2IntOpenHashMap<O> second) { for(Iterator<Object2IntMap.Entry<O>> iter = second.object2IntEntrySet().fastIterator(); iter.hasNext();) { Object2IntMap.Entry<O> entry = iter.next(); second.addTo(entry.getKey(), entry.getIntValue()); } }
Example 8
Source File: DictionaryValuesWriter.java From parquet-mr with Apache License 2.0 | 5 votes |
@Override public void fallBackDictionaryEncodedData(ValuesWriter writer) { //build reverse dictionary Binary[] reverseDictionary = new Binary[getDictionarySize()]; for (Object2IntMap.Entry<Binary> entry : binaryDictionaryContent.object2IntEntrySet()) { reverseDictionary[entry.getIntValue()] = entry.getKey(); } //fall back to plain encoding IntIterator iterator = encodedValues.iterator(); while (iterator.hasNext()) { int id = iterator.next(); writer.writeBytes(reverseDictionary[id]); } }
Example 9
Source File: DictionaryBasedGroupKeyGenerator.java From incubator-pinot with Apache License 2.0 | 5 votes |
@Nonnull @Override public Iterator<GroupKey> iterator() { return new Iterator<GroupKey>() { private final ObjectIterator<Object2IntMap.Entry<IntArray>> _iterator = _rawKeyToGroupIdMap.object2IntEntrySet().fastIterator(); private final GroupKey _groupKey = new GroupKey(); @Override public boolean hasNext() { return _iterator.hasNext(); } @Override public GroupKey next() { Object2IntMap.Entry<IntArray> entry = _iterator.next(); _groupKey._groupId = entry.getIntValue(); _groupKey._stringKey = getGroupKey(entry.getKey()); return _groupKey; } @Override public void remove() { throw new UnsupportedOperationException(); } }; }
Example 10
Source File: ASTAssociation.java From symja_android_library with GNU General Public License v3.0 | 5 votes |
protected IAST normal(IBuiltInSymbol symbol) { IASTMutable list = F.ast(symbol, argSize(), true); for (Object2IntMap.Entry<IExpr> element : map.object2IntEntrySet()) { int value = element.getIntValue(); if (value < 0) { value *= -1; list.set(value, F.RuleDelayed(element.getKey(), get(value))); } else { list.set(value, F.Rule(element.getKey(), get(value))); } } return list; }
Example 11
Source File: ASTAssociation.java From symja_android_library with GNU General Public License v3.0 | 5 votes |
@Override public ArrayList<String> keyNames() { ArrayList<String> list = new ArrayList<String>(); for (Object2IntMap.Entry<IExpr> element : map.object2IntEntrySet()) { list.add(element.getKey().toString()); } return list; }
Example 12
Source File: ASTAssociation.java From symja_android_library with GNU General Public License v3.0 | 5 votes |
protected IASTMutable keys(IBuiltInSymbol symbol) { IASTMutable list = F.ast(symbol, argSize(), true); for (Object2IntMap.Entry<IExpr> element : map.object2IntEntrySet()) { // for (Map.Entry<IExpr, Integer> element : map.entrySet()) { int value = element.getIntValue(); if (value < 0) { value *= -1; } list.set(value, element.getKey()); } return list; }
Example 13
Source File: ASTAssociation.java From symja_android_library with GNU General Public License v3.0 | 5 votes |
@Override public IAST getItems(int[] items, int length) { ASTAssociation assoc = new ASTAssociation(length, false); if (length > 0) { if (length <= 5) { for (int i = 0; i < length; i++) { for (Object2IntMap.Entry<IExpr> element : map.object2IntEntrySet()) { int value = element.getIntValue(); if (value < 0) { value *= -1; if (value == items[i]) { assoc.appendRule(F.RuleDelayed(element.getKey(), get(value))); break; } } else { if (value == items[i]) { assoc.appendRule(F.Rule(element.getKey(), get(value))); break; } } } } return assoc; } IAST ast = normal(false); for (int i = 0; i < length; i++) { assoc.appendRule((IAST) ast.get(items[i])); } } return assoc; }
Example 14
Source File: IntegerFunctions.java From symja_android_library with GNU General Public License v3.0 | 4 votes |
@Override public IExpr evaluate(final IAST ast, EvalEngine engine) { IExpr result = F.NIL; int radix = 10; if (ast.isAST1()) { result = F.IntegerDigits.of(engine, ast.arg1()); } else if (ast.size() >= 3) { radix = ast.arg2().toIntDefault(); if (radix <= 0) { return F.NIL; } result = F.IntegerDigits.of(engine, ast.arg1(), ast.arg2()); } if (result.isList()) { IAST list = (IAST) result; Object2IntOpenHashMap<IExpr> map = new Object2IntOpenHashMap<IExpr>(); for (int i = 1; i < list.size(); i++) { map.addTo((IExpr) list.get(i), 1); } if (ast.isAST3()) { int index = ast.arg3().toIntDefault(); if (index > 0 && index < radix) { int count = map.getInt(F.ZZ(index)); return F.ZZ(count); } return F.NIL; } if (Config.MAX_AST_SIZE < radix ) { ASTElementLimitExceeded.throwIt(radix); } IExpr[] arr = new IExpr[radix]; for (int i = 0; i < arr.length; i++) { arr[i] = F.C0; } for (Object2IntMap.Entry<IExpr> element : map.object2IntEntrySet()) { IExpr key = element.getKey(); int k = key.toIntDefault(); if (k == 0) { arr[radix - 1] = F.ZZ(element.getIntValue()); } else if (k > 0 && k < radix) { arr[k - 1] = F.ZZ(element.getIntValue()); } else { return F.NIL; } } return F.ast(arr, F.List); } return F.NIL; }
Example 15
Source File: ASTAssociation.java From symja_android_library with GNU General Public License v3.0 | 4 votes |
@Override public IAssociation sort(Comparator<IExpr> comp) { List<Integer> indices = new ArrayList<Integer>(argSize()); for (int i = 1; i < size(); i++) { indices.add(i); } Comparator<Integer> comparator; if (comp == null) { comparator = new Comparator<Integer>() { @Override public int compare(Integer i, Integer j) { return get(i).compareTo(get(j)); } }; } else { comparator = new Comparator<Integer>() { @Override public int compare(Integer i, Integer j) { return comp.compare(get(i), get(j)); } }; } Collections.sort(indices, comparator); ASTAssociation result = new ASTAssociation(argSize(), true); for (Object2IntMap.Entry<IExpr> element : map.object2IntEntrySet()) { // for (Map.Entry<IExpr, Integer> element : map.entrySet()) { int value = element.getIntValue(); int indx = value; if (indx < 0) { indx *= -1; } for (int i = 0; i < indices.size(); i++) { if (indices.get(i) == indx) { indx = i + 1; break; } } int newValue = indices.get(indx - 1); result.set(indx, get(newValue)); if (value < 0) { result.map.put(element.getKey(), -indx); } else { result.map.put(element.getKey(), indx); } } return result; }