Materializes the kNNs and RkNNs of the specified object IDs.

@param ids the IDs of the objects
510623
private void materializeKNNAndRKNNs(ArrayDBIDs ids, FiniteProgress progress) {
    // add an empty list to each rknn
    for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
      if(materialized_RkNN.get(iter) == null) {
        materialized_RkNN.put(iter, new TreeSet<DoubleDBIDPair>());
      }
    }

    // knn query
    List<? extends KNNList> kNNList = knnQuery.getKNNForBulkDBIDs(ids, k);
    for(DBIDArrayIter id = ids.iter(); id.valid(); id.advance()) {
      KNNList kNNs = kNNList.get(id.getOffset());
      storage.put(id, kNNs);
      for(DoubleDBIDListIter iter = kNNs.iter(); iter.valid(); iter.advance()) {
        materialized_RkNN.get(iter).add(DBIDUtil.newPair(iter.doubleValue(), id));
      }
      LOG.incrementProcessed(progress);
    }

    LOG.ensureCompleted(progress);
  }
192642
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();
      // look for new kNNs
      KNNHeap heap = null;
      for(DBIDIter newid = ids.iter(); newid.valid(); newid.advance()) {
        double dist = distanceQuery.distance(id, newid);
        if(dist <= knnDist) {
          // New id changes the kNNs of oldid.
          heap = heap != null ? heap : DBIDUtil.newHeap(oldkNNs);
          heap.insert(dist, newid);
        }
      }
      // kNNs for oldid have changed:
      if(heap != null) {
        KNNList newkNNs = heap.toKNNList();
        storage.put(id, newkNNs);

        // get the difference
        ModifiableDoubleDBIDList added = DBIDUtil.newDistanceDBIDList(),
            removed = DBIDUtil.newDistanceDBIDList();
        DoubleDBIDListIter olditer = oldkNNs.iter(), newiter = newkNNs.iter();
        while(olditer.valid() && newiter.valid()) {
          if(DBIDUtil.equal(olditer, newiter)) {
            olditer.advance();
            newiter.advance();
            continue;
          }
          double newd = newiter.doubleValue(), oldd = olditer.doubleValue();
          if(newd < oldd || (newd == oldd && !oldkNNs.contains(newiter))) {
            added.add(newiter.doubleValue(), newiter);
            newiter.advance();
          }
          else if(oldd < newd || (oldd == newd && !newkNNs.contains(olditer))) {
            removed.add(olditer.doubleValue(), olditer);
            olditer.advance();
          }
          else {
            throw new IllegalStateException("Unexpected third case, needs debug!");
          }
        }
        for(; olditer.valid(); olditer.advance()) {
          removed.add(olditer.doubleValue(), olditer);
        }
        for(; newiter.valid(); newiter.advance()) {
          added.add(newiter.doubleValue(), newiter);
        }
        // add new RkNN
        for(DoubleDBIDListIter newnn = added.iter(); newnn.valid(); newnn.advance()) {
          materialized_RkNN.get(newnn).add(DBIDUtil.newPair(newnn.doubleValue(), id));
        }
        // remove old RkNN
        for(DoubleDBIDListIter oldnn = removed.iter(); oldnn.valid(); oldnn.advance()) {
          materialized_RkNN.get(oldnn).remove(DBIDUtil.newPair(oldnn.doubleValue(), id));
        }

        rkNN_ids.add(id);
      }
    }
    return rkNN_ids;
  }
782420
protected void objectsInserted(DBIDs ids) {
    final Logging log = getLogger(); // Could be subclass
    StepProgress stepprog = log.isVerbose() ? new StepProgress(3) : null;

    ArrayDBIDs aids = DBIDUtil.ensureArray(ids);
    // materialize the new kNNs
    log.beginStep(stepprog, 1, "New insertions ocurred, materialize their new kNNs.");
    // Bulk-query kNNs
    List<? extends KNNList> kNNList = knnQuery.getKNNForBulkDBIDs(aids, k);
    // Store in storage
    DBIDIter iter = aids.iter();
    for(int i = 0; i < aids.size(); i++, iter.advance()) {
      storage.put(iter, kNNList.get(i));
    }

    // update the affected kNNs
    log.beginStep(stepprog, 2, "New insertions ocurred, update the affected kNNs.");
    ArrayDBIDs rkNN_ids = updateKNNsAfterInsertion(ids);

    // inform listener
    log.beginStep(stepprog, 3, "New insertions ocurred, inform listeners.");
    fireKNNsInserted(ids, rkNN_ids);

    log.setCompleted(stepprog);
  }
1038168
public String[] lookupString(int[] ids) {
		String[] vals = new String[ids.length];
		for(int i = 0; i < ids.length; i++)	{
			vals[i] = index.get(ids[i]);
		}
		return vals;
	}
878966
public void setFaceIds(java.util.Collection<String> faceIds) {
        if (faceIds == null) {
            this.faceIds = null;
            return;
        }

        this.faceIds = new java.util.ArrayList<String>(faceIds);
    }
401642
public static SetDBIDs ensureSet(DBIDs ids) {
    return ids instanceof SetDBIDs ? (SetDBIDs) ids : newHashSet(ids);
  }
1315768
static void render(FacesContext context, final Set<String> ids) {
        if (ids.isEmpty()) {
            return;
        }
        final Collection<String> renderIds = context.getPartialViewContext().getRenderIds();
        final char separatorChar = getSeparatorChar(context);
        for (String id : ids) {
            renderIds.add(id.substring(id.indexOf(separatorChar) + 1));
        }
    }
342591
@Override
    public IdsBuilder append(final int... ids) {
        return doAppend(Arrays.asList(InternalUtils.wrap(ids)));
    }
503592
public DoubleDBIDList getRKNN(DBIDRef id) {
    TreeSet<DoubleDBIDPair> rKNN = materialized_RkNN.get(id);
    if(rKNN == null) {
      return null;
    }
    ModifiableDoubleDBIDList ret = DBIDUtil.newDistanceDBIDList(rKNN.size());
    for(DoubleDBIDPair pair : rKNN) {
      ret.add(pair);
    }
    ret.sort();
    return ret;
  }
1050212
public List<T> list(List<Long> ids)
    {
        List<T> ret = new ArrayList<T>();

        if(ids != null)
        {
            for(Long id : ids)
            {
                T resource = get(id);
                if(resource != null)
                    ret.add(resource);
            }
        }

        return ret;
    }
143028
private void linearScanBatchKNN(ArrayDBIDs ids, List<KNNHeap> heaps) {
    final DistanceQuery<O> dq = distanceQuery;
    // The distance is computed on database IDs
    for(DBIDIter iter = getRelation().getDBIDs().iter(); iter.valid(); iter.advance()) {
      int index = 0;
      for(DBIDIter iter2 = ids.iter(); iter2.valid(); iter2.advance(), index++) {
        KNNHeap heap = heaps.get(index);
        heap.insert(dq.distance(iter2, iter), iter);
      }
    }
  }
834855
public void setPhoneNumberIds(java.util.Collection<String> phoneNumberIds) {
        if (phoneNumberIds == null) {
            this.phoneNumberIds = null;
            return;
        }

        this.phoneNumberIds = new java.util.ArrayList<String>(phoneNumberIds);
    }
1116155
public void setResourceIds(java.util.Collection<String> resourceIds) {
        if (resourceIds == null) {
            this.resourceIds = null;
            return;
        }

        this.resourceIds = new com.amazonaws.internal.SdkInternalList<String>(resourceIds);
    }
195145
public void setInstanceIds(java.util.Collection<InstanceIdDetail> instanceIds) {
        if (instanceIds == null) {
            this.instanceIds = null;
            return;
        }

        this.instanceIds = new java.util.ArrayList<InstanceIdDetail>(instanceIds);
    }
769467
private ArrayDBIDs updateKNNsAfterDeletion(DBIDs ids) {
    SetDBIDs idsSet = DBIDUtil.ensureSet(ids);
    ArrayModifiableDBIDs rkNN_ids = DBIDUtil.newArray();
    for(DBIDIter iditer = relation.iterDBIDs(); iditer.valid(); iditer.advance()) {
      KNNList kNNs = storage.get(iditer);
      for(DBIDIter it = kNNs.iter(); it.valid(); it.advance()) {
        if(idsSet.contains(it)) {
          rkNN_ids.add(iditer);
          break;
        }
      }
    }

    // update the kNNs of the RkNNs
    List<? extends KNNList> kNNList = knnQuery.getKNNForBulkDBIDs(rkNN_ids, k);
    DBIDIter iter = rkNN_ids.iter();
    for(int i = 0; i < rkNN_ids.size(); i++, iter.advance()) {
      storage.put(iter, kNNList.get(i));
    }

    return rkNN_ids;
  }
615856
private void fillDensities(KNNQuery<O> knnq, DBIDs ids, WritableDoubleDataStore dens) {
    FiniteProgress prog = LOG.isVerbose() ? new FiniteProgress("Densities", ids.size(), LOG) : null;
    for(DBIDIter iter = ids.iter(); iter.valid(); iter.advance()) {
      final KNNList neighbors = knnq.getKNNForDBID(iter, k);
      dens.putDouble(iter, neighbors.getKNNDistance());
      LOG.incrementProcessed(prog);
    }
    LOG.ensureCompleted(prog);
  }
1176774
public QueryBuilder removeParentIds(final Collection<Integer> ids) {
        if (ids != null) {
            parentIds.removeAll(ids);
        }
        return this;
    }