Java Code Examples for it.unimi.dsi.fastutil.ints.Int2ObjectMap#keySet()

The following examples show how to use it.unimi.dsi.fastutil.ints.Int2ObjectMap#keySet() . 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: DioriteRandomUtils.java    From Diorite with MIT License 6 votes vote down vote up
@Nullable
public static <T> T getWeightedRandomReversed(Random random, Int2ObjectMap<T> choices)
{
    long i = 0;
    IntSet ints = choices.keySet();
    for (IntIterator iterator = ints.iterator(); iterator.hasNext(); )
    {
        int x = iterator.nextInt();
        i += x;
    }
    i = getRandomLong(random, 0, i);
    for (Int2ObjectMap.Entry<T> entry : choices.int2ObjectEntrySet())
    {
        i -= entry.getIntKey();
        if (i < 0)
        {
            return entry.getValue();
        }
    }
    return null;
}
 
Example 2
Source File: CustomTimeBucketRegistry.java    From attic-apex-malhar with Apache License 2.0 6 votes vote down vote up
private int initialize(Int2ObjectMap<CustomTimeBucket> idToTimeBucket)
{
  Preconditions.checkNotNull(idToTimeBucket);

  int tempId = Integer.MIN_VALUE;

  for (int timeBucketId : idToTimeBucket.keySet()) {
    tempId = Math.max(tempId, timeBucketId);
    CustomTimeBucket customTimeBucket = idToTimeBucket.get(timeBucketId);
    textToTimeBucket.put(customTimeBucket.getText(), customTimeBucket);
    Preconditions.checkNotNull(customTimeBucket);
    timeBucketToId.put(customTimeBucket, timeBucketId);
  }

  return tempId;
}