Skip to content

Commit

Permalink
Implement remove_ids in IndexPQ (facebookresearch#407)
Browse files Browse the repository at this point in the history
* Implement remove_ids in IndexPQ

* Update IndexPQ.cpp
  • Loading branch information
myl2821 authored and mdouze committed Apr 20, 2018
1 parent 1ae7494 commit ed809ce
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
22 changes: 22 additions & 0 deletions IndexPQ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <algorithm>

#include "FaissAssert.h"
#include "AuxIndexStructures.h"
#include "hamming.h"

namespace faiss {
Expand Down Expand Up @@ -84,6 +85,27 @@ void IndexPQ::add (idx_t n, const float *x)
}


long IndexPQ::remove_ids (const IDSelector & sel)
{
idx_t j = 0;
for (idx_t i = 0; i < ntotal; i++) {
if (sel.is_member (i)) {
// should be removed
} else {
if (i > j) {
memmove (&codes[pq.code_size * j], &codes[pq.code_size * i], pq.code_size);
}
j++;
}
}
long nremove = ntotal - j;
if (nremove > 0) {
ntotal = j;
codes.resize (ntotal * pq.code_size);
}
return nremove;
}


void IndexPQ::reset()
{
Expand Down
5 changes: 5 additions & 0 deletions IndexPQ.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ struct IndexPQ: Index {

Search_type_t search_type;

/** remove some ids. NB that Because of the structure of the
* indexing structre, the semantics of this operation are
* different from the usual ones: the new ids are shifted */
long remove_ids(const IDSelector& sel) override;

// just encode the sign of the components, instead of using the PQ encoder
// used only for the queries
bool encode_signs;
Expand Down

0 comments on commit ed809ce

Please sign in to comment.