@Override
protected void objectsRemoved(DBIDs ids) {
StepProgress stepprog = getLogger().isVerbose() ? new StepProgress(3) : null;
ArrayDBIDs aids = DBIDUtil.ensureArray(ids);
// delete the materialized (old) kNNs and RkNNs
if(stepprog != null) {
stepprog.beginStep(1, "New deletions ocurred, remove their materialized kNNs and RkNNs.", getLogger());
}
List<List<DistanceResultPair<D>>> kNNs = new ArrayList<List<DistanceResultPair<D>>>(ids.size());
List<List<DistanceResultPair<D>>> rkNNs = new ArrayList<List<DistanceResultPair<D>>>(ids.size());
for(DBID id : aids) {
kNNs.add(storage.get(id));
storage.delete(id);
rkNNs.add(new ArrayList<DistanceResultPair<D>>(materialized_RkNN.get(id)));
materialized_RkNN.delete(id);
}
ArrayDBIDs kNN_ids = extractAndRemoveIDs(kNNs, aids);
ArrayDBIDs rkNN_ids = extractAndRemoveIDs(rkNNs, aids);
// update the affected kNNs and RkNNs
if(stepprog != null) {
stepprog.beginStep(2, "New deletions ocurred, update the affected kNNs and RkNNs.", getLogger());
}
// update the kNNs of the RkNNs
List<List<DistanceResultPair<D>>> kNNList = knnQuery.getKNNForBulkDBIDs(rkNN_ids, k);
for(int i = 0; i < rkNN_ids.size(); i++) {
DBID id = rkNN_ids.get(i);
storage.put(id, kNNList.get(i));
for(DistanceResultPair<D> kNN : kNNList.get(i)) {
Set<DistanceResultPair<D>> rknns = materialized_RkNN.get(kNN.getDBID());
rknns.add(new GenericDistanceResultPair<D>(kNN.getDistance(), id));
}