JASSv2
Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | List of all members
JASS::query_heap< ACCUMULATOR_ARRAY > Class Template Reference

Everything necessary to process a query (using a heap) is encapsulated in an object of this type. More...

#include <query_heap.h>

Inheritance diagram for JASS::query_heap< ACCUMULATOR_ARRAY >:
Inheritance graph
[legend]
Collaboration diagram for JASS::query_heap< ACCUMULATOR_ARRAY >:
Collaboration graph
[legend]

Public Member Functions

 query_heap (compress_integer &codex)
 Constructor.
 
virtual ~query_heap ()
 Destructor.
 
virtual void init (const std::vector< std::string > &primary_keys, DOCID_TYPE documents=1024, DOCID_TYPE top_k=10, size_t width=7)
 Initialise the object. MUST be called before first use. More...
 
virtual docid_rsv_pairget_first (void)
 Retrun the top result. More...
 
virtual docid_rsv_pairget_next (void)
 After calling get_first(), return the next result. More...
 
virtual void rewind (ACCUMULATOR_TYPE smallest_possible_rsv=0, ACCUMULATOR_TYPE top_k_lower_bound=1, ACCUMULATOR_TYPE largest_possible_rsv=0)
 Clear this object after use and ready for re-use.
 
virtual void sort (void)
 sort this resuls list before iteration over it.
 
forceinline void add_rsv (DOCID_TYPE document_id, ACCUMULATOR_TYPE score)
 Add weight to the rsv for document document_id. More...
 
virtual void decode_with_writer (size_t integers, const void *compressed, size_t compressed_size)
 Given the integer decoder, the number of integes to decode, and the compressed sequence, decompress (but do not process). More...
 
- Public Member Functions inherited from JASS::query
 query (compress_integer &codex)
 Constructor.
 
virtual ~query ()
 Destructor.
 
template<typename STRING_TYPE >
void parse (const STRING_TYPE &query, parser_query::parser_type which_parser=parser_query::parser_type::query)
 Take the given query and parse it. More...
 
query_term_listterms (void)
 Return a reference to the parsed query. More...
 
forceinline void set_impact (ACCUMULATOR_TYPE score)
 Set the impact score to use in a push_back(). More...
 
forceinline void decode_and_process (ACCUMULATOR_TYPE impact, size_t integers, const void *compressed, size_t compressed_size)
 Given the integer decoder, the number of integes to decode, and the compressed sequence, decompress (but do not process). More...
 
virtual void decode_with_writer (query::printer &writer, size_t integers, const void *compressed, size_t compressed_size)
 Given the integer decoder, the number of integes to decode, and the compressed sequence, decompress (but do not process). More...
 

Static Public Member Functions

static void unittest (void)
 Unit test this class.
 

Private Types

typedef pointer_box< ACCUMULATOR_TYPEaccumulator_pointer
 

Private Attributes

ACCUMULATOR_ARRAY accumulators
 The accumulators, one per document in the collection.
 
DOCID_TYPE needed_for_top_k
 The number of results we still need in order to fill the top-k.
 
ACCUMULATOR_TYPE zero
 Constant zero used for pointer dereferenced comparisons.
 
accumulator_pointer accumulator_pointers [MAX_TOP_K]
 Array of pointers to the top k accumulators.
 
heap< accumulator_pointertop_results
 Heap containing the top-k results.
 
bool sorted
 has heap and accumulator_pointers been sorted (false after rewind() true after sort())
 
ACCUMULATOR_TYPE top_k_lower_bound
 Lowest possible score to enter the top k.
 
docid_rsv_pair next_result
 A single result, used but get_first() and get_next()
 
DOCID_TYPE next_result_location
 Used by get_first() and get_next() to determine which result is next.
 

Additional Inherited Members

- Public Types inherited from JASS::query
typedef uint8_t ACCUMULATOR_TYPE
 the type of an accumulator (probably a uint16_t)
 
typedef uint32_t DOCID_TYPE
 the type of a document id (from a compressor)
 
- Public Attributes inherited from JASS::query
DOCID_TYPE top_k
 The number of results to track.
 
- Static Public Attributes inherited from JASS::query
static constexpr size_t MAX_DOCUMENTS = 200'000'000
 the maximum number of documents an index can hold
 
static constexpr size_t MAX_TOP_K = 1'000
 the maximum top-k value
 
static constexpr size_t MAX_RSV = (std::numeric_limits<ACCUMULATOR_TYPE>::max)()
 
- Protected Attributes inherited from JASS::query
ACCUMULATOR_TYPE impact
 The impact score to be added on a call to add_rsv()
 
allocator_pool memory
 All memory allocation happens in this "arena".
 
std::vector< DOCID_TYPEdecompress_buffer
 The delta-encoded decopressed integer sequence.
 
DOCID_TYPE documents
 The numnber of documents this index contains.
 
parser_query parser
 Parser responsible for converting text into a parsed query.
 
query_term_listparsed_query
 The parsed query.
 
const std::vector< std::string > * primary_keys
 A vector of strings, each the primary key for the document with an id equal to the vector index.
 
compress_integercodex
 The decompressor to use.
 

Detailed Description

template<typename ACCUMULATOR_ARRAY>
class JASS::query_heap< ACCUMULATOR_ARRAY >

Everything necessary to process a query (using a heap) is encapsulated in an object of this type.

Member Function Documentation

◆ add_rsv()

template<typename ACCUMULATOR_ARRAY >
forceinline void JASS::query_heap< ACCUMULATOR_ARRAY >::add_rsv ( DOCID_TYPE  document_id,
ACCUMULATOR_TYPE  score 
)
inline

Add weight to the rsv for document document_id.

Parameters
document_id[in] which document to increment
score[in] the amount of weight to add

◆ decode_with_writer()

template<typename ACCUMULATOR_ARRAY >
virtual void JASS::query_heap< ACCUMULATOR_ARRAY >::decode_with_writer ( size_t  integers,
const void *  compressed,
size_t  compressed_size 
)
inlinevirtual

Given the integer decoder, the number of integes to decode, and the compressed sequence, decompress (but do not process).

Parameters
integers[in] The number of integers that are compressed.
compressed[in] The compressed sequence.
compressed_size[in] The length of the compressed sequence.

Implements JASS::query.

◆ get_first()

template<typename ACCUMULATOR_ARRAY >
virtual docid_rsv_pair* JASS::query_heap< ACCUMULATOR_ARRAY >::get_first ( void  )
inlinevirtual

Retrun the top result.

Returns
The first (i.e. top) result in the results list.

Implements JASS::query.

◆ get_next()

template<typename ACCUMULATOR_ARRAY >
virtual docid_rsv_pair* JASS::query_heap< ACCUMULATOR_ARRAY >::get_next ( void  )
inlinevirtual

After calling get_first(), return the next result.

Returns
The next result in the results list, or NULL if at end of list

Implements JASS::query.

◆ init()

template<typename ACCUMULATOR_ARRAY >
virtual void JASS::query_heap< ACCUMULATOR_ARRAY >::init ( const std::vector< std::string > &  primary_keys,
DOCID_TYPE  documents = 1024,
DOCID_TYPE  top_k = 10,
size_t  width = 7 
)
inlinevirtual

Initialise the object. MUST be called before first use.

Parameters
primary_keys[in] Vector of the document primary keys used to convert from internal document ids to external primary keys.
documents[in] The number of documents in the collection.
top_k[in] The top-k documents to return from the query once executed.
width[in] The width of the 2-d accumulators (if they are being used).

Reimplemented from JASS::query.


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