Gaia
gaia2::BaseSearchSpace< SearchPointType, DataSetType > Class Template Reference

A SearchSpace is a structure dedicated to the task of storing pointers to Point with an associated distance and is the structure on which the nearest-neighbours queries are performed. More...

#include <searchspace.h>

Inheritance diagram for gaia2::BaseSearchSpace< SearchPointType, DataSetType >:

Public Member Functions

 BaseSearchSpace (const Filter *filter=0, bool ownsFilter=false)
 
 BaseSearchSpace (const BaseSearchSpace< SearchPointType, DataSetType > &other)
 Copy constructor. More...
 
void copyPointsFrom (const BaseSearchSpace< SearchPointType, DataSetType > &other)
 Copy all the points from the other SearchSpace into this one. More...
 
int size () const
 Returns the total number of points contained in this SearchSpace.
 
int unfilteredSize () const
 Returns the size of this SearchSpace, before filtering the points. More...
 
void clear ()
 Clears the whole SearchSpace.
 
SearchResults get (int n, int offset=0)
 Returns the list of search results, which are pairs of (pointName, distance). More...
 
void limit (int n)
 This method limits the number of results contained in this SearchSpace. More...
 
void thresholdLimit (float maxDist)
 This method limits the bymber of results contained in this SearchSpace. More...
 
const Filterfilter ()
 
void setFilter (const Filter *filter, bool ownsFilter=false)
 
void invalidate ()
 Mark this SearchSpace as neither sorted nor filtered.
 
void filterAll ()
 Filters all points so that the remaining points at the end all comply to the Filter.
 
void pointerSort ()
 Sorts the SearchPoints contained into this SearchSpace by order of their pointer address.
 
void addPoints (const DataSetType *dataset, const QList< QString > &ids)
 Add the points from the dataset with the given IDs to this SearchSpace.
 
void removePoints (const QList< QString > &ids)
 Remove the points with the given IDs from this SearchSpace.
 
void setIntersection (const BaseSearchSpace< SearchPointType, DataSetType > *other)
 This computes the intersection of this SearchSpace with the other one. More...
 
void setUnion (const BaseSearchSpace< SearchPointType, DataSetType > *other)
 This computes the union of this SearchSpace with the other one. More...
 
void setDifference (const BaseSearchSpace< SearchPointType, DataSetType > *other)
 This computes the difference of this SearchSpace and the other one (ie: this - other). More...
 
QString pointName (const SearchPointType &p) const
 
const PointrefPoint (const SearchPointType &p) const
 
bool validPoint (const SearchPointType &p) const
 
template<typename PointType , typename DistanceType >
void computeDistance (const PointType &query, const DistanceType *dist)
 Compute the distance from the given query point to all those contained in this SearchSpace, and presort a few points to have near instant access to them.
 
void setDataSet (const DataSetType *dataset)
 
const DataSetType * dataSet () const
 
void filterAndSort (int n=1000)
 Filters the points in this SearchSpace using the given Filter and sort them by increasing distance. More...
 
void cleanSearchSpace ()
 

Static Public Member Functions

static BaseSearchSpace< SearchPointType, DataSetType > * createFromDataSet (const DataSetType *dataset)
 
static BaseSearchSpace< SearchPointType, DataSetType > * createFromPoints (const DataSetType *dataset, const QList< QString > &pointNames)
 

Protected Member Functions

int validUpTo () const
 Index in the search space up to which points are actually filtered and sorted.
 
void sortAll ()
 

Protected Attributes

const DataSetType * _dataset
 
const Filter_filter
 
bool _ownsFilter
 
int _sortedUpTo
 
int _filteredUpTo
 

Friends

template<typename SearchPointType2 , typename DataSetType2 >
class BaseQueryOptimizer
 

Detailed Description

template<typename SearchPointType, typename DataSetType>
class gaia2::BaseSearchSpace< SearchPointType, DataSetType >

A SearchSpace is a structure dedicated to the task of storing pointers to Point with an associated distance and is the structure on which the nearest-neighbours queries are performed.

It is also what is returned by the view as a search result, and allows to get any number of points with a given offset if desired.

Some pre-indexed SearchSpace instances will reside in a SearchSpace pool which is owned by a specific View. It acts as an index, and the pool has a way to either add more of those, or return a given subset that satisfies certain conditions. As such, when a View needs to be revalidated, it will also revalidate all linked SearchSpace.

WARNING: As we make copies of SearchSpace to perform queries, it is perfectly safe to make multithreaded queries. However, it is NOT safe to add or remove points while there is still a query being processed, or a SearchSpace returned from a previous query still in use (ie: View instances revalidate themselves automatically when a DataSet changes, but SearchSpace ones don't)

Constructor & Destructor Documentation

template<typename SearchPointType , typename DataSetType >
BaseSearchSpace::BaseSearchSpace ( const BaseSearchSpace< SearchPointType, DataSetType > &  other)

Copy constructor.

WARNING: this does not copy the filter nor any other member variables, only the points contained in the SearchSpace.

Member Function Documentation

template<typename SearchPointType , typename DataSetType >
void BaseSearchSpace::copyPointsFrom ( const BaseSearchSpace< SearchPointType, DataSetType > &  other)

Copy all the points from the other SearchSpace into this one.

WARNING: this does not copy the filter nor any other member variables, only the points contained in the SearchSpace.

Referenced by gaia2::BaseView< DataSetType, PointType, SearchPointType, DistanceType >::getSearchSpace().

template<typename SearchPointType , typename DataSetType >
void BaseSearchSpace::filterAndSort ( int  n = 1000)

Filters the points in this SearchSpace using the given Filter and sort them by increasing distance.

Parameters
nonly filter and sort the n points with the smallest distance, this has the advantage of being much faster than sorting all the points. If n <= 0, then all the points will be sorted.

Referenced by gaia2::BaseView< DataSetType, PointType, SearchPointType, DistanceType >::nnSearch().

template<typename SearchPointType , typename DataSetType >
SearchResults BaseSearchSpace::get ( int  n,
int  offset = 0 
)

Returns the list of search results, which are pairs of (pointName, distance).

Parameters
nthe number of desired results
offsetthe start offset
template<typename SearchPointType , typename DataSetType >
void BaseSearchSpace::limit ( int  n)

This method limits the number of results contained in this SearchSpace.

If there were fewer points before than the given number, the SearchSpace is left untouched, otherwise it will have a maximum of n points after the call.

template<typename SearchPointType , typename DataSetType >
void BaseSearchSpace::setDifference ( const BaseSearchSpace< SearchPointType, DataSetType > *  other)

This computes the difference of this SearchSpace and the other one (ie: this - other).

NB: This function assumes that both SearchSpaces have their points ordered by pointer address.

template<typename SearchPointType , typename DataSetType >
void BaseSearchSpace::setIntersection ( const BaseSearchSpace< SearchPointType, DataSetType > *  other)

This computes the intersection of this SearchSpace with the other one.

NB: This function assumes that both SearchSpaces have their points ordered by pointer address.

Referenced by gaia2::BaseQueryOptimizer< SearchPointType, DataSetType >::optimize().

template<typename SearchPointType , typename DataSetType >
void BaseSearchSpace::setUnion ( const BaseSearchSpace< SearchPointType, DataSetType > *  other)

This computes the union of this SearchSpace with the other one.

NB: This function assumes that both SearchSpaces have their points ordered by pointer address.

Referenced by gaia2::BaseQueryOptimizer< SearchPointType, DataSetType >::optimize().

template<typename SearchPointType , typename DataSetType >
void BaseSearchSpace::thresholdLimit ( float  maxDist)

This method limits the bymber of results contained in this SearchSpace.

All the results which have a distance higher than the specified maxDist will be discarded from this SearchSpace.

template<typename SearchPointType , typename DataSetType >
int BaseSearchSpace::unfilteredSize ( ) const

Returns the size of this SearchSpace, before filtering the points.

WARNING: use with care, this value might not be consistent with what you expect.


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