public final class TopNScoredIdAccumulator extends Object implements ScoredIdAccumulator
Accumulate the top N scored IDs. IDs are sorted by their associated scores.
Constructor and Description |
---|
TopNScoredIdAccumulator(int n)
Create a new accumulator to accumulate the top n IDs.
|
Modifier and Type | Method and Description |
---|---|
List<ScoredId> |
finish()
Accumulate the scores into a sorted scored list and reset the accumulator.
|
LongList |
finishList()
Accumulate the scored items into a list.
|
Long2DoubleMap |
finishMap()
Accumulate the scores into a map and reset the accumulator.
|
LongSet |
finishSet()
Accumulate the scored items into a set.
|
MutableSparseVector |
finishVector()
Accumulate the scores into a mutable sparse vector and reset the accumulator.
|
boolean |
isEmpty()
Query whether the accumulator is empty.
|
void |
put(long item,
double score)
Put a new item in the accumulator.
|
int |
size()
Get the number of items in the accumulator.
|
public TopNScoredIdAccumulator(int n)
Create a new accumulator to accumulate the top n IDs.
n
- The number of IDs to retain.public boolean isEmpty()
ScoredIdAccumulator
Query whether the accumulator is empty.
isEmpty
in interface ScoredIdAccumulator
true
if the accumulator has no items.public int size()
ScoredIdAccumulator
Get the number of items in the accumulator.
size
in interface ScoredIdAccumulator
public void put(long item, double score)
ScoredIdAccumulator
Put a new item in the accumulator. Putting the same item twice does not replace the previous entry - it adds a new entry with the same ID.
put
in interface ScoredIdAccumulator
item
- The item to add to the accumulator.score
- The item’s score.public List<ScoredId> finish()
ScoredIdAccumulator
Accumulate the scores into a sorted scored list and reset the accumulator. Items are sorted in decreasing order of score.
After this method is called, the accumulator is ready for another accumulation.
finish
in interface ScoredIdAccumulator
public MutableSparseVector finishVector()
ScoredIdAccumulator
Accumulate the scores into a mutable sparse vector and reset the accumulator.
After this method is called, the accumulator is ready for another accumulation.
finishVector
in interface ScoredIdAccumulator
public Long2DoubleMap finishMap()
ScoredIdAccumulator
Accumulate the scores into a map and reset the accumulator.
After this method is called, the accumulator is ready for another accumulation.
finishMap
in interface ScoredIdAccumulator
public LongSet finishSet()
ScoredIdAccumulator
Accumulate the scored items into a set.
finishSet
in interface ScoredIdAccumulator
public LongList finishList()
ScoredIdAccumulator
Accumulate the scored items into a list.
finishList
in interface ScoredIdAccumulator