validateParams(vecid, pairs);
if (!indexer.containsKey(vecid)) {
_add(vecid, pairs);
} else {
TIntList indexes = new TIntArrayList();
TIntFloatMap results = new TIntFloatHashMap();
float max = Float.NEGATIVE_INFINITY;
int cursor = indexer.get(vecid);
int length = lengths.get(vecid);
while (length > 0) {
int pos = (int) data.get(cursor++);
float val = data.get(cursor++);
results.put(pos, val);
if (val > max) {
max = val;
}
indexes.add(pos);
length -= 2;
}
cursor = 0;
while (cursor < pairs.length) {
int pos = pairs[cursor++];
float val = (float) pairs[cursor++];
if (results.containsKey(pos)) {
val = results.get(pos) + val;
results.put(pos, val);
if (val > max) {
max = val;
}
} else {
results.put(pos, val);
indexes.add(pos);
}
}
indexes.sort();
int start = data.size();
indexer.put(vecid, start);
lengths.put(vecid, indexes.size() * 2);
TIntIterator iter = indexes.iterator();
if (max < accumuFactor * sparseFactor) {
while (iter.hasNext()) {
int key = iter.next();
float value = results.get(key);
data.add(key);
data.add(value);
}
} else {
while (iter.hasNext()) {
int key = iter.next();
float value = results.get(key) * accumuFactor / max;
data.add(key);
data.add(value);
}
}