Java Code Examples for it.unimi.dsi.fastutil.ints.Int2IntMap#Entry

The following examples show how to use it.unimi.dsi.fastutil.ints.Int2IntMap#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: LayeredLabelPropagation.java    From fasten with Apache License 2.0 6 votes vote down vote up
public Iterator<Int2IntMap.Entry> entries() {
	return new ObjectIterator<>() {
		private int i;

		private final Entry entry = new Entry();

		@Override
		public boolean hasNext() {
			return i < n;
		}

		@Override
		public Entry next() {
			if (!hasNext()) throw new NoSuchElementException();
			final int l = location[i++];
			entry.setKey(key[l]);
			entry.setValue(count[l]);
			return entry;
		}
	};
}
 
Example 2
Source File: AbstractIdMap.java    From WorldGrower with GNU General Public License v3.0 6 votes vote down vote up
@Override
public final int findBestId(Predicate<WorldObject> predicate, World world) {
	int bestId = -1;
	int bestRelationshipValue = Integer.MIN_VALUE;
	for(Int2IntMap.Entry entry : idsToValue.int2IntEntrySet()) {
		int id = entry.getIntKey();
		int relationshipValue = entry.getIntValue();
		
		// id may not exist in world because it's filtered out by
		// WorldFacade, for example being invisible
		if (world.exists(id)) {
			WorldObject person = world.findWorldObjectById(id);
			
			if (relationshipValue > bestRelationshipValue && predicate.test(person)) {
				bestRelationshipValue = relationshipValue;
				bestId = id;
			}
		}
	}
	
	return bestId;
}
 
Example 3
Source File: AbstractIdMap.java    From WorldGrower with GNU General Public License v3.0 6 votes vote down vote up
@Override
public final int findWorstId(World world) {
	int worstId = -1;
	int worstRelationshipValue = Integer.MAX_VALUE;
	for(Int2IntMap.Entry entry : idsToValue.int2IntEntrySet()) {
		int id = entry.getIntKey();
		int relationshipValue = entry.getIntValue();
		
		if (relationshipValue < worstRelationshipValue) {
			worstRelationshipValue = relationshipValue;
			worstId = id;
		}
	}
	
	return worstId;
}
 
Example 4
Source File: AbstractIdMap.java    From WorldGrower with GNU General Public License v3.0 6 votes vote down vote up
@Override
public final int findBestId(Predicate<WorldObject> predicate, Comparator<WorldObject> comparator,  World world) {
	WorldObject bestPerson = null;
	for(Int2IntMap.Entry entry : idsToValue.int2IntEntrySet()) {
		int id = entry.getIntKey();
		// id may not exist in world because it's filtered out by
		// WorldFacade, for example being invisible
		if (world.exists(id)) {
			WorldObject person = world.findWorldObjectById(id);
			
			if (predicate.test(person)) {
				if (bestPerson == null || comparator.compare(bestPerson, person) < 0) {
					bestPerson = person;
				}
			}
		}
	}
	
	if (bestPerson != null) {
		return bestPerson.getProperty(Constants.ID);
	} else {
		return -1;
	}
}
 
Example 5
Source File: DictionaryBasedGroupKeyGenerator.java    From incubator-pinot with Apache License 2.0 6 votes vote down vote up
@Nonnull
@Override
public Iterator<GroupKey> iterator() {
  return new Iterator<GroupKey>() {
    private final ObjectIterator<Int2IntMap.Entry> _iterator = _rawKeyToGroupIdMap.int2IntEntrySet().fastIterator();
    private final GroupKey _groupKey = new GroupKey();

    @Override
    public boolean hasNext() {
      return _iterator.hasNext();
    }

    @Override
    public GroupKey next() {
      Int2IntMap.Entry entry = _iterator.next();
      _groupKey._groupId = entry.getIntValue();
      _groupKey._stringKey = getGroupKey(entry.getIntKey());
      return _groupKey;
    }

    @Override
    public void remove() {
      throw new UnsupportedOperationException();
    }
  };
}
 
Example 6
Source File: HashInstance.java    From jstarcraft-ai with Apache License 2.0 5 votes vote down vote up
@Override
public HashInstance iterateQualityFeatures(QualityAccessor accessor) {
    for (Int2IntMap.Entry term : this.qualityFeatures.int2IntEntrySet()) {
        accessor.accessorFeature(term.getIntKey(), term.getIntValue());
    }
    return this;
}
 
Example 7
Source File: CustomHashMap.java    From kourami with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public boolean union(CustomHashMap other){
boolean modified = false;
for(Int2IntMap.Entry otherEntry : other.int2IntEntrySet()){
    if(!this.containsKey(otherEntry.getIntKey())){
	this.put(otherEntry.getIntKey(), otherEntry.getIntValue());
	modified = true;
    }
}
return modified;
   }
 
Example 8
Source File: AbstractIdMap.java    From WorldGrower with GNU General Public License v3.0 5 votes vote down vote up
@Override
public final int getSumOfAllValues() {
	int sumOfAllValues = 0;
	for(Int2IntMap.Entry entry : idsToValue.int2IntEntrySet()) {
		sumOfAllValues += entry.getIntValue();
	}
	return sumOfAllValues;
}
 
Example 9
Source File: AbstractIntegerSym.java    From symja_android_library with GNU General Public License v3.0 5 votes vote down vote up
protected static IAST factorBigInteger(BigInteger number, boolean isNegative, int numerator, int denominator,
		Int2IntMap map) {
	if (number.compareTo(BigInteger.valueOf(7)) <= 0) {
		return F.NIL;
	}
	BigInteger rest = Primality.countPrimes32749(number, map);
	if (map.size() == 0) {
		return F.NIL;
	}
	IASTAppendable result = F.TimesAlloc(map.size() + 4);
	boolean evaled = false;
	for (Int2IntMap.Entry entry : map.int2IntEntrySet()) {
		int key = entry.getIntKey();
		int value = entry.getIntValue();
		int mod = value % denominator;
		int div = value / denominator;
		if (div != 0) {
			result.append(F.Power(valueOf(key), F.ZZ(div)));
			if (mod != 0) {
				result.append(F.Power(valueOf(key), F.QQ(mod, denominator)));
			}
			evaled = true;
		} else {
			result.append(F.Power(F.Power(valueOf(key), valueOf(value)), F.QQ(1, denominator)));
		}
	}
	if (evaled) {
		if (!rest.equals(BigInteger.ONE)) {
			result.append(F.Power(valueOf(rest), F.QQ(1, denominator)));
		}
		if (isNegative) {
			result.append(F.Power(F.CN1, F.QQ(numerator, denominator)));
		}
		return result;
	}
	return F.NIL;
}