LongList ids = new LongArrayList(ratings.size());
for (Rating r: ratings) {
ids.add(dimension.getId(r));
}
LongKeyDomain keys = LongKeyDomain.fromCollection(ids, false);
MutableSparseVector msv = MutableSparseVector.create(keys.domain());
long[] timestamps = null;
// check for fast-path, where each item has one rating
if (keys.domainSize() < ratings.size()) {
timestamps = new long[keys.domainSize()];
}
for (Rating r: ratings) {
long id = dimension.getId(r);
if (timestamps != null) {
int idx = keys.getIndex(id);
if (keys.indexIsActive(idx) && timestamps[idx] >= r.getTimestamp()) {
continue; // we have seen a newer event - skip this.
} else {
timestamps[idx] = r.getTimestamp();
keys.setActive(idx, true);
}
}
Preference p = r.getPreference();
if (p != null) {