private ArrayDBIDs updateKNNsAndRkNNs(DBIDs ids){
  ArrayModifiableDBIDs rkNN_ids=DBIDUtil.newArray();
  DBIDs oldids=DBIDUtil.difference(relation.getDBIDs(),ids);
  for (DBIDIter id=oldids.iter(); id.valid(); id.advance()) {
    KNNList oldkNNs=storage.get(id);
    double knnDist=oldkNNs.getKNNDistance();
    KNNHeap heap=null;
    for (DBIDIter newid=ids.iter(); newid.valid(); newid.advance()) {
      double dist=distanceQuery.distance(id,newid);
      if (dist <= knnDist) {
        if (heap == null) {
          heap=DBIDUtil.newHeap(oldkNNs);
        }
        heap.insert(dist,newid);
      }
    }
    if (heap != null) {
      KNNList newkNNs=heap.toKNNList();
      storage.put(id,newkNNs);
      int i=0;
      int j=0;
      ModifiableDoubleDBIDList added=DBIDUtil.newDistanceDBIDList();
      ModifiableDoubleDBIDList removed=DBIDUtil.newDistanceDBIDList();
      while (i < oldkNNs.size() && j < newkNNs.size()) {
        DoubleDBIDPair drp1=oldkNNs.get(i);
        DoubleDBIDPair drp2=newkNNs.get(j);
        if (!DBIDUtil.equal(drp1,drp2)) {
          added.add(drp2);
          j++;
        }
 else {
          i++;
          j++;
        }
      }
      if (i != j) {
        for (; i < oldkNNs.size(); i++) {
          removed.add(oldkNNs.get(i));
        }
        for (; j < newkNNs.size(); i++) {
          added.add(newkNNs.get(i));
        }
      }
      for (DoubleDBIDListIter newnn=added.iter(); newnn.valid(); newnn.advance()) {
        TreeSet<DoubleDBIDPair> rknns=materialized_RkNN.get(newnn);
        rknns.add(makePair(newnn,id));
      }
      for (DoubleDBIDListIter oldnn=removed.iter(); oldnn.valid(); oldnn.advance()) {
        TreeSet<DoubleDBIDPair> rknns=materialized_RkNN.get(oldnn);
        rknns.remove(makePair(oldnn,id));
      }
      rkNN_ids.add(id);
    }
  }
  return rkNN_ids;
}

private ArrayDBIDs updateKNNsAndRkNNs ( DBIDs ids ) { ArrayModifiableDBIDs rkNN_ids = DBIDUtil . newArray ( ) ; DBIDs oldids = DBIDUtil . difference ( relation . getDBIDs ( ) , ids ) ; for ( DBIDIter id = oldids . iter ( ) ; id . valid ( ) ; id . advance ( ) ) { KNNList oldkNNs = storage . get ( id ) ; double knnDist = oldkNNs . getKNNDistance ( ) ; KNNHeap heap = null ; for ( DBIDIter newid = ids . iter ( ) ; newid . valid ( ) ; newid . advance ( ) ) { double dist = distanceQuery . distance ( id , newid ) ; if ( dist <= knnDist ) { if ( heap == null ) { heap = DBIDUtil . newHeap ( oldkNNs ) ; } heap . insert ( dist , newid ) ; } } if ( heap != null ) { KNNList newkNNs = heap . toKNNList ( ) ; storage . put ( id , newkNNs ) ; int i = 0 ; int j = 0 ; ModifiableDoubleDBIDList added = DBIDUtil . newDistanceDBIDList ( ) ; ModifiableDoubleDBIDList removed = DBIDUtil . newDistanceDBIDList ( ) ; while ( i < oldkNNs . size ( ) && j < newkNNs . size ( ) ) { DoubleDBIDPair drp1 = oldkNNs . get ( i ) ; DoubleDBIDPair drp2 = newkNNs . get ( j ) ; if ( ! DBIDUtil . equal ( drp1 , drp2 ) ) { added . add ( drp2 ) ; j ++ ; } else { i ++ ; j ++ ; } } if ( i != j ) { for ( ; i < oldkNNs . size ( ) ; i ++ ) { removed . add ( oldkNNs . get ( i ) ) ; } for ( ; j < newkNNs . size ( ) ; i ++ ) { added . add ( newkNNs . get ( i ) ) ; } } for ( DoubleDBIDListIter newnn = added . iter ( ) ; newnn . valid ( ) ; newnn . advance ( ) ) { TreeSet < DoubleDBIDPair > rknns = materialized_RkNN . get ( newnn ) ; rknns . add ( makePair ( newnn , id ) ) ; } for ( DoubleDBIDListIter oldnn = removed . iter ( ) ; oldnn . valid ( ) ; oldnn . advance ( ) ) { TreeSet < DoubleDBIDPair > rknns = materialized_RkNN . get ( oldnn ) ; rknns . remove ( makePair ( oldnn , id ) ) ; } rkNN_ids . add ( id ) ; } } return rkNN_ids ; }
updates the knns and rknns after insertion of the specified ids .
