backends/flint/flint_utils.h File Reference

#include <xapian/types.h>
#include <string>

Include dependency graph for flint_utils.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define CASSERT(a)   {char assert[(a) ? 1 : -1];(void)assert;}
 Compile time assert a condition.
#define CASSERT_TYPE_UNSIGNED(T)   CASSERT(static_cast<T>(-1) > 0)
 Compile time assert that type T is unsigned.

Typedefs

typedef unsigned char om_byte
typedef unsigned int om_uint32
typedef int om_int32

Functions

template<class T>
bool unpack_uint (const char **src, const char *src_end, T *resultptr)
 Reads an unsigned integer from a string starting at a given position.
template<class T>
string pack_uint (T value)
 Generates a packed representation of an integer.
template<>
string pack_uint< bool > (bool value)
 Generates a packed representation of a bool.
template<class T>
bool unpack_uint_last (const char **src, const char *src_end, T *resultptr)
 Reads an unsigned integer from a string starting at a given position.
template<class T>
string pack_uint_last (T value)
 Generates a packed representation of an integer.
template<class T>
string pack_uint_preserving_sort (T value)
 Generate a packed representation of an integer, preserving sort order.
template<class T>
bool unpack_uint_preserving_sort (const char **src, const char *src_end, T *resultptr)
 Unpack a unsigned integer, store in sort preserving order.
bool unpack_string (const char **src, const char *src_end, string &result)
string pack_string (string value)
string pack_string_preserving_sort (string value)
 Pack a string into a representation which preserves sort order.
bool unpack_string_preserving_sort (const char **src, const char *src_end, string &result)
bool unpack_bool (const char **src, const char *src_end, bool *resultptr)
string pack_bool (bool value)
string flint_docid_to_key (Xapian::docid did)
 Convert a document id to a key (suitable when the docid is the only component of the key).


Define Documentation

#define CASSERT (  )     {char assert[(a) ? 1 : -1];(void)assert;}

Compile time assert a condition.

Definition at line 33 of file flint_utils.h.

Referenced by QuartzRecordTable::get_doccount(), FlintRecordTable::get_doccount(), unpack_uint(), and unpack_uint_last().

#define CASSERT_TYPE_UNSIGNED (  )     CASSERT(static_cast<T>(-1) > 0)

Compile time assert that type T is unsigned.

Definition at line 36 of file flint_utils.h.

Referenced by QuartzRecordTable::get_doccount(), FlintRecordTable::get_doccount(), pack_uint(), pack_uint_last(), pack_uint_preserving_sort(), unpack_uint(), and unpack_uint_last().


Typedef Documentation

typedef unsigned char om_byte

Definition at line 38 of file flint_utils.h.

typedef unsigned int om_uint32

Definition at line 39 of file flint_utils.h.

typedef int om_int32

Definition at line 40 of file flint_utils.h.


Function Documentation

template<class T>
bool unpack_uint ( const char **  src,
const char *  src_end,
T *  resultptr 
) [inline]

Reads an unsigned integer from a string starting at a given position.

Parameters:
src A pointer to a pointer to the data to read. The character pointer will be updated to point to the next character to read, or 0 if the method ran out of data. (It is only set to 0 in case of an error).
src_end A pointer to the byte after the end of the data to read the integer from.
resultptr A pointer to a place to store the result. If an error occurs, the value stored in this location is undefined. If this pointer is 0, the result is not stored, and the method simply skips over the result.
Returns:
True if an integer was successfully read. False if the read failed. Failure may either be due to the data running out (in which case *src will equal 0), or due to the value read overflowing the size of result (in which case *src will point to wherever the value ends, despite the overflow).

Definition at line 68 of file flint_utils.h.

References CASSERT, and CASSERT_TYPE_UNSIGNED.

Referenced by check_table(), FlintTermList::FlintTermList(), FlintTermListTable::get_doclength(), FlintAllDocsPostList::get_doclength(), QuartzRecordTable::get_lastdocid(), QuartzRecordTable::get_total_length(), main(), merge_postlists(), PositionCursor::next(), PostlistCursor::next(), QuartzTermList::next(), FlintTermList::next(), QuartzPositionList::next_internal(), FlintPositionListTable::positionlist_count(), QuartzTermList::QuartzTermList(), QuartzPositionList::read_data(), FlintPositionList::read_data(), read_did_increase(), FlintDatabase::read_metainfo(), QuartzPostList::read_number_of_entries(), FlintPostList::read_number_of_entries(), read_start_of_chunk(), read_start_of_first_chunk(), read_wdf_and_length(), test_packint2(), test_unpackint1(), QuartzValueTable::unpack_entry(), FlintValueTable::unpack_entry(), and unpack_string().

template<class T>
string pack_uint ( value  )  [inline]

Generates a packed representation of an integer.

Parameters:
value The integer to represent.
Returns:
A string containing the representation of the integer.

Definition at line 125 of file flint_utils.h.

References CASSERT_TYPE_UNSIGNED.

Referenced by QPostlistChunkWriter::append(), PostlistChunkWriter::append(), QuartzValueTable::encode_values(), FlintValueTable::encode_values(), FlintWritableDatabase::flush_postlist_changes(), main(), make_key(), make_start_of_chunk(), make_start_of_first_chunk(), make_wdf_and_length(), merge_postlists(), PositionCursor::next(), pack_string(), QuartzTermListTable::set_entries(), QuartzPositionListTable::set_positionlist(), FlintPositionListTable::set_positionlist(), FlintTermListTable::set_termlist(), QuartzRecordTable::set_total_length_and_lastdocid(), test_packint1(), test_packint2(), and write_start_of_chunk().

template<>
string pack_uint< bool > ( bool  value  )  [inline]

Generates a packed representation of a bool.

This is a specialisation of the template above.

Parameters:
value The bool to represent.
Returns:
A string containing the representation of the bool.

template<class T>
bool unpack_uint_last ( const char **  src,
const char *  src_end,
T *  resultptr 
) [inline]

Reads an unsigned integer from a string starting at a given position.

This encoding requires that we know the encoded length from out-of-band information (so is suitable when only one integer is encoded, or for the last integer encoded).

Parameters:
src A pointer to a pointer to the data to read.
src_end A pointer to the byte after the end of the data to read the integer from.
resultptr A pointer to a place to store the result. If an error occurs, the value stored in this location is undefined. If this pointer is 0, the result is not stored, and the method simply skips over the result.
Returns:
True if an integer was successfully read. False if the read failed. Failure can hapen if the value read overflows the size of result.

Definition at line 177 of file flint_utils.h.

References CASSERT, and CASSERT_TYPE_UNSIGNED.

Referenced by check_table(), FlintSpellingWordsList::get_termfreq(), QuartzRecordTable::get_total_length(), FlintSpellingTable::get_word_frequency(), main(), merge_postlists(), merge_spellings(), DocIDKeyedCursor::next(), QuartzAllDocsPostList::QuartzAllDocsPostList(), and FlintDatabase::read_metainfo().

template<class T>
string pack_uint_last ( value  )  [inline]

Generates a packed representation of an integer.

This encoding requires that we know the encoded length from out-of-band information (so is suitable when only one integer is encoded, or for the last integer encoded).

Parameters:
value The integer to represent.
Returns:
A string containing the representation of the integer.

Definition at line 212 of file flint_utils.h.

References CASSERT_TYPE_UNSIGNED.

Referenced by FlintWritableDatabase::flush_postlist_changes(), main(), FlintSpellingTable::merge_changes(), merge_postlists(), merge_spellings(), DocIDKeyedCursor::next(), quartz_docid_to_key(), and QuartzRecordTable::set_total_length_and_lastdocid().

template<class T>
string pack_uint_preserving_sort ( value  )  [inline]

Generate a packed representation of an integer, preserving sort order.

This representation is less compact than the usual one, and has a limit of 256 bytes on the length of the integer. However, this is unlikely to ever be a problem.

Parameters:
value The integer to represent.
Returns:
A string containing the representation of the integer.

Definition at line 237 of file flint_utils.h.

References CASSERT_TYPE_UNSIGNED.

Referenced by flint_docid_to_key(), main(), make_key(), FlintPostListTable::make_key(), FlintPositionListTable::make_key(), merge_docid_keyed(), merge_postlists(), FlintPositionListTable::positionlist_count(), FlintPositionList::read_data(), FlintAllDocsPostList::skip_to(), and test_packint3().

template<class T>
bool unpack_uint_preserving_sort ( const char **  src,
const char *  src_end,
T *  resultptr 
) [inline]

Unpack a unsigned integer, store in sort preserving order.

Parameters:
src A pointer to a pointer to the data to read. The character pointer will be updated to point to the next character to read, or 0 if the method ran out of data. (It is only set to 0 in case of an error).
src_end A pointer to the byte after the end of the data to read the integer from.
resultptr A pointer to a place to store the result. If an error occurs, the value stored in this location is undefined. If this pointer is 0, the result is not stored, and the method simply skips over the result.
Returns:
True if an integer was successfully read. False if the read failed. Failure may either be due to the data running out (in which case *src will equal 0), or due to the value read overflowing the size of result (in which case *src will point to wherever the value ends, despite the overflow).

Definition at line 273 of file flint_utils.h.

Referenced by check_table(), QPostlistChunkWriter::flush(), PostlistChunkWriter::flush(), QuartzPostListTable::get_chunk(), FlintPostListTable::get_chunk(), merge_docid_keyed(), QuartzPostList::move_to_chunk_containing(), FlintPostList::move_to_chunk_containing(), PostlistCursor::next(), QuartzPostList::next_chunk(), FlintPostList::next_chunk(), FlintAllDocsPostList::read_did_from_current_key(), and test_packint3().

bool unpack_string ( const char **  src,
const char *  src_end,
string &  result 
) [inline]

Definition at line 307 of file flint_utils.h.

References unpack_uint().

Referenced by check_table(), QuartzValueTable::unpack_entry(), and FlintValueTable::unpack_entry().

string pack_string ( string  value  )  [inline]

Definition at line 328 of file flint_utils.h.

References pack_uint().

Referenced by QuartzValueTable::encode_values(), and FlintValueTable::encode_values().

string pack_string_preserving_sort ( string  value  )  [inline]

Pack a string into a representation which preserves sort order.

We do this by replacing zero bytes in the string with a zero byte followed by byte value 0xff, and then appending two zero bytes to the end.

Definition at line 339 of file flint_utils.h.

Referenced by FlintAllTermsList::FlintAllTermsList(), make_key(), FlintPostListTable::make_key(), QuartzAllTermsList::QuartzAllTermsList(), QuartzAllTermsList::skip_to(), FlintAllTermsList::skip_to(), QuartzDatabase::term_exists(), and test_packstring1().

bool unpack_string_preserving_sort ( const char **  src,
const char *  src_end,
string &  result 
) [inline]

Definition at line 351 of file flint_utils.h.

Referenced by check_table(), get_tname_from_key(), PostlistCursor::next(), QuartzAllTermsList::next(), FlintAllTermsList::next(), QuartzAllTermsList::QuartzAllTermsList(), FlintAllTermsList::skip_to(), and test_packstring1().

bool unpack_bool ( const char **  src,
const char *  src_end,
bool *  resultptr 
) [inline]

Definition at line 376 of file flint_utils.h.

Referenced by check_table(), QuartzTermList::QuartzTermList(), and read_start_of_chunk().

string pack_bool ( bool  value  )  [inline]

Definition at line 397 of file flint_utils.h.

Referenced by make_start_of_chunk(), QuartzTermListTable::set_entries(), and write_start_of_chunk().

string flint_docid_to_key ( Xapian::docid  did  )  [inline]

Convert a document id to a key (suitable when the docid is the only component of the key).

Definition at line 406 of file flint_utils.h.

References pack_uint_preserving_sort().

Referenced by FlintRecordTable::delete_record(), FlintTermListTable::delete_termlist(), FlintTermList::FlintTermList(), FlintTermListTable::get_doclength(), FlintRecordTable::get_record(), make_key(), FlintRecordTable::replace_record(), and FlintTermListTable::set_termlist().


Documentation for Xapian (version 1.0.10).
Generated on 24 Dec 2008 by Doxygen 1.5.2.