KGraph
 All Classes Namespaces Functions Pages
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
kgraph::KGraph Class Referenceabstract

The KGraph index. More...

#include <kgraph.h>

Classes

struct  IndexInfo
 Information and statistics of the indexing algorithm. More...
 
struct  IndexParams
 Indexing parameters. More...
 
struct  SearchInfo
 Information and statistics of the search algorithm. More...
 
struct  SearchParams
 Search parameters. More...
 

Public Types

enum  { FORMAT_DEFAULT = 0, FORMAT_NO_DIST = 1 }
 

Public Member Functions

virtual void load (char const *path)=0
 Load index from file. More...
 
virtual void save (char const *path, int format=FORMAT_DEFAULT) const =0
 Save index to file. More...
 
virtual void build (IndexOracle const &oracle, IndexParams const &params, IndexInfo *info=0)=0
 Build the index.
 
virtual void prune (IndexOracle const &oracle, unsigned level)=0
 Prune the index. More...
 
unsigned search (SearchOracle const &oracle, SearchParams const &params, unsigned *ids, SearchInfo *info=0) const
 Online k-NN search. More...
 
virtual unsigned search (SearchOracle const &oracle, SearchParams const &params, unsigned *ids, float *dists, SearchInfo *info) const =0
 Online k-NN search. More...
 
virtual void get_nn (unsigned id, unsigned *nns, unsigned *M, unsigned *L) const
 Get offline computed k-NNs of a given object. More...
 
virtual void get_nn (unsigned id, unsigned *nns, float *dists, unsigned *M, unsigned *L) const =0
 Get offline computed k-NNs of a given object. More...
 
virtual void reverse (int)=0
 

Static Public Member Functions

static KGraphcreate ()
 Constructor.
 
static char const * version ()
 Returns version string.
 

Detailed Description

The KGraph index.

This is an abstract base class. Use KGraph::create to create an instance.

Member Function Documentation

virtual void kgraph::KGraph::get_nn ( unsigned  id,
unsigned *  nns,
unsigned *  M,
unsigned *  L 
) const
inlinevirtual

Get offline computed k-NNs of a given object.

See the full version of get_nn.

virtual void kgraph::KGraph::get_nn ( unsigned  id,
unsigned *  nns,
float *  dists,
unsigned *  M,
unsigned *  L 
) const
pure virtual

Get offline computed k-NNs of a given object.

The user must provide space to save IndexParams::L values. The actually returned L could be smaller than IndexParams::L, and M <= L is the number of neighbors KGraph thinks could be most useful for online search, and is usually < L. If the index has been pruned, the returned L could be smaller than IndexParams::L used to construct the index.

id Object ID whose neighbor information are returned. nns Neighbor IDs, must have space to save IndexParams::L values. dists Distance values, must have space to save IndexParams::L values. M Useful number of neighbors, output only. L Actually returned number of neighbors, output only.

virtual void kgraph::KGraph::load ( char const *  path)
pure virtual

Load index from file.

Parameters
pathPath to the index file.
virtual void kgraph::KGraph::prune ( IndexOracle const &  oracle,
unsigned  level 
)
pure virtual

Prune the index.

Pruning makes the index smaller to save memory, and makes online search on the pruned index faster. (The cost parameters of online search must be enlarged so accuracy is not reduced.)

Currently only two pruning levels are supported:

  • PRUNE_LEVEL_1 = 1: Only reduces index size, fast.
  • PRUNE_LEVEL_2 = 2: For improve online search speed, slow.

No pruning is done if level = 0.

virtual void kgraph::KGraph::save ( char const *  path,
int  format = FORMAT_DEFAULT 
) const
pure virtual

Save index to file.

Parameters
pathPath to the index file.
unsigned kgraph::KGraph::search ( SearchOracle const &  oracle,
SearchParams const &  params,
unsigned *  ids,
SearchInfo info = 0 
) const
inline

Online k-NN search.

Search results are guaranteed to be ranked in ascending order of distance.

Parameters
idsPointer to the memory where neighbor IDs are stored, must have space to save params.K ids.
virtual unsigned kgraph::KGraph::search ( SearchOracle const &  oracle,
SearchParams const &  params,
unsigned *  ids,
float *  dists,
SearchInfo info 
) const
pure virtual

Online k-NN search.

Search results are guaranteed to be ranked in ascending order of distance.

Parameters
idsPointer to the memory where neighbor IDs are stored, must have space to save params.K values.
distsPointer to the memory where distances are stored, must have space to save params.K values.

The documentation for this class was generated from the following file: