Commit abe2b0fd authored by dengos's avatar dengos Committed by Matthijs Douze

read/write index with std::function wrapper (#427)

* add access function to IndexIVF;

* - access for IndexIVF;
- write_index/read_index with std::function<...>;

* - fix test compile on mac;
- adjust write/read with std::function;

* replace std::function with IOReader/IOWriter;

* remove IndexIVF::access // tmp

* PFN_WRITE/READ => WRITE;

* revert mac compile fix;

* rename;

* fix compile;

* reset CMakeList;

* format; remove unused function/header;
parent 433f5c0f
...@@ -590,7 +590,6 @@ void IndexIVF::copy_subset_to (IndexIVF & other, int subset_type, ...@@ -590,7 +590,6 @@ void IndexIVF::copy_subset_to (IndexIVF & other, int subset_type,
} }
IndexIVF::~IndexIVF() IndexIVF::~IndexIVF()
{ {
if (own_invlists) { if (own_invlists) {
......
This diff is collapsed.
...@@ -21,17 +21,21 @@ struct Index; ...@@ -21,17 +21,21 @@ struct Index;
struct VectorTransform; struct VectorTransform;
struct IndexIVF; struct IndexIVF;
struct ProductQuantizer; struct ProductQuantizer;
struct IOReader;
struct IOWriter;
void write_index (const Index *idx, FILE *f); void write_index (const Index *idx, FILE *f);
void write_index (const Index *idx, const char *fname); void write_index (const Index *idx, const char *fname);
void write_index (const Index *idx, IOWriter *writer);
const int IO_FLAG_MMAP = 1; const int IO_FLAG_MMAP = 1;
const int IO_FLAG_READ_ONLY = 2; const int IO_FLAG_READ_ONLY = 2;
Index *read_index (FILE * f, int io_flags = 0); Index *read_index (FILE * f, int io_flags = 0);
Index *read_index (const char *fname, int io_flags = 0); Index *read_index (const char *fname, int io_flags = 0);
Index *read_index (IOReader *reader, int io_flags = 0);
void write_VectorTransform (const VectorTransform *vt, const char *fname); void write_VectorTransform (const VectorTransform *vt, const char *fname);
...@@ -55,6 +59,21 @@ struct Cloner { ...@@ -55,6 +59,21 @@ struct Cloner {
virtual ~Cloner() {} virtual ~Cloner() {}
}; };
struct IOReader {
// fread
virtual size_t operator()(
void *ptr, size_t size, size_t nitems) = 0;
virtual ~IOReader() {}
};
struct IOWriter {
// fwrite
virtual size_t operator()(
const void *ptr, size_t size, size_t nitems) = 0;
virtual ~IOWriter() {}
};
} }
#endif #endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment