MetricKnn API
Fast Similarity Search using the Metric Space Approach
|
Represents a set of objects of any type. More...
#include <mknn_dataset.hpp>
Inherited by mknn::DatasetConcatenate, and mknn::DatasetMultiObject.
Public Member Functions | |
Dataset () | |
Default constructor. | |
virtual | ~Dataset () |
Default destructor. | |
Dataset (const Dataset &other) | |
Copy constructor. | |
Dataset & | operator= (const Dataset &other) |
Assignment operator. | |
Using the dataset | |
long long | getNumObjects () |
Size of the dataset. More... | |
void * | getObject (long long pos) |
Retrieves the object in position pos in dataset . More... | |
void | pushObject (void *object) |
Adds an object to a dataset. More... | |
Domain | getDomain () |
Returns the domain assigned to the dataset. More... | |
void * | getCompactVectors () |
The objects in the dataset are stored in a single long array. More... | |
void | printObjectsToTextFile (std::string filename_write) |
It saves the objects in a dataset in text format. More... | |
Protected Attributes | |
std::unique_ptr< Impl > | pimpl |
opaque object | |
Friends | |
class | DatasetLoader |
class | Distance |
class | Index |
class | PredefDistance |
class | Resolver |
Load/Save datasets | |
void | save (std::string filename_write) |
The dataset is saved to a file. More... | |
static Dataset | restore (std::string filename_read) |
Loads a dataset from a file. More... | |
Represents a set of objects of any type.
Objects in dataset are type void*
. In order to use some pre-defined distance, the objects in the dataset must have defined a Domain.
void* mknn::Dataset::getCompactVectors | ( | ) |
The objects in the dataset are stored in a single long array.
The format of the created data is similar to the input described in DatasetLoader::PointerCompactVectors.
The dataset must contain vectors (i.e., the domain in the dataset must belong to some constant in mknn::Domain::GENERAL_DOMAIN_VECTOR.
The type of the returned array (float*
, double*
, ...) depends on the domain datatype.
The returned pointer is cached, thus consecutive calls do not compact again the vectors. The cache is released together with the dataset. If an object is added to a dynamic dataset after the call to this method, the cache is released it will not be added.
Domain mknn::Dataset::getDomain | ( | ) |
Returns the domain assigned to the dataset.
Do not modify or free the returned domain.
long long mknn::Dataset::getNumObjects | ( | ) |
Size of the dataset.
dataset
void* mknn::Dataset::getObject | ( | long long | pos | ) |
Retrieves the object in position pos
in dataset
.
pos | the position of the object to retrieve. It must be a number between 0 and getNumObjects - 1 . |
void mknn::Dataset::printObjectsToTextFile | ( | std::string | filename_write | ) |
It saves the objects in a dataset in text format.
This method is useful for reviewing the objects that are inside a dataset.
filename_write | Filename to write or overwrite. |
void mknn::Dataset::pushObject | ( | void * | object | ) |
Adds an object to a dataset.
The dataset must be dynamic in order to support this method (see DatasetLoader::Empty).
object | the new object to add at the end of the dataset. |
|
static |
Loads a dataset from a file.
The file must have been created by save.
filename_read | File to read. If the file does not exists an error is raised. |
void mknn::Dataset::save | ( | std::string | filename_write | ) |
The dataset is saved to a file.
It may create other files using filename_write
as prefix. The created files may be in binary format for fast loading.
filename_write | File to create. If the file already exists it is overwritten. |