Tagcoll::TDBDiskIndex< ITEM, TAG > Class Template Reference

Full TaggedCollection implementation on top of a persistent on-disk TDB database. More...

#include <TDBDiskIndex.h>

Inheritance diagram for Tagcoll::TDBDiskIndex< ITEM, TAG >:

Inheritance graph
[legend]
Collaboration diagram for Tagcoll::TDBDiskIndex< ITEM, TAG >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 TDBDiskIndex (const std::string &pkgidx, const std::string &tagidx, const Converter< ITEM, std::string > &fromitem, const Converter< TAG, std::string > &fromtag, const Converter< std::string, ITEM > &toitem, const Converter< std::string, TAG > &totag, bool write=true)
 Create a new TDBDiskIndex.
virtual ~TDBDiskIndex ()
virtual bool hasTag (const TAG &tag) const
 Check if the collection contains a tag.
virtual OpSet< ITEM > getTaggedItems () const
 Get the set of all the items that have tags according to this collection.
virtual OpSet< TAG > getAllTags () const
 Get the set of all the tags in this collection.
virtual int getCardinality (const TAG &tag) const
 Get the cardinality of tag `tag' (that is, the number of items who have it).
virtual void output (Consumer< ITEM, TAG > &consumer) const
 Output all the contents of the collection to a Consumer.
virtual void applyChange (const PatchList< ITEM, TAG > &change)
 Apply a patch to the collection.
template<>
OpSet< string > getItemsHavingTag (const string &tag) const
template<>
OpSet< string > getTagsOfItem (const string &item) const

Protected Member Functions

virtual void consumeItem (const ITEM &item, const OpSet< TAG > &tags)
 Process a tagged item, with its tags.
virtual void consumeItems (const OpSet< ITEM > &items, const OpSet< TAG > &tags)
 Process a set of items identically tagged, with their tags.
virtual OpSet< ITEM > getItemsHavingTag (const TAG &tag) const
 Get the items which are tagged with at least the tag `tag'.
virtual OpSet< TAG > getTagsOfItem (const ITEM &item) const
 Get the tags attached to an item.

Protected Attributes

TDBFile pkgdb
TDBFile tagdb
const Converter< ITEM, std::string > & fromitem
const Converter< TAG, std::string > & fromtag
const Converter< std::string,
ITEM > & 
toitem
const Converter< std::string,
TAG > & 
totag

Detailed Description

template<class ITEM, class TAG>
class Tagcoll::TDBDiskIndex< ITEM, TAG >

Full TaggedCollection implementation on top of a persistent on-disk TDB database.

It allows to efficiently query a collection without having to store it all into memory.

If used for heavy modifications, the performance is slower compared to other in-memory collections. If database writes are mainly used for populating the index, then TDBIndexer should be used to create the index and TDBDiskIndex to access it afterwards.


Constructor & Destructor Documentation

template<class ITEM, class TAG>
TDBDiskIndex::TDBDiskIndex ( const std::string &  pkgidx,
const std::string &  tagidx,
const Converter< ITEM, std::string > &  fromitem,
const Converter< TAG, std::string > &  fromtag,
const Converter< std::string, ITEM > &  toitem,
const Converter< std::string, TAG > &  totag,
bool  write = true 
)

Create a new TDBDiskIndex.

Parameters:
pkgidx The file name of the package index
tagidx The file name of the tag index
fromitem,fromtag,toitem,totag The Converter-s used to convert ITEMS and TAGS to and from strings. If 0 is passed, this TDBDiskIndex will only be able to work with string items and string tags.
write Set to false if the index should be opened in read-only mode. If opened in read-only mode, all non-const methods of this class will throw an exception if invoked. It defaults to true.

template<class ITEM, class TAG>
virtual Tagcoll::TDBDiskIndex< ITEM, TAG >::~TDBDiskIndex (  )  [inline, virtual]


Member Function Documentation

template<class ITEM, class TAG>
void TDBDiskIndex::consumeItem ( const ITEM &  item,
const OpSet< TAG > &  tags 
) [protected, virtual]

Process a tagged item, with its tags.

Implements Tagcoll::Consumer< ITEM, TAG >.

template<class ITEM, class TAG>
void TDBDiskIndex::consumeItems ( const OpSet< ITEM > &  items,
const OpSet< TAG > &  tags 
) [protected, virtual]

Process a set of items identically tagged, with their tags.

Reimplemented from Tagcoll::Consumer< ITEM, TAG >.

template<class ITEM, class TAG>
OpSet< ITEM > TDBDiskIndex::getItemsHavingTag ( const TAG &  tag  )  const [protected, virtual]

Get the items which are tagged with at least the tag `tag'.

Returns:
The items found, or an empty set if no items have that tag

Implements Tagcoll::ReadonlyCollection< ITEM, TAG >.

template<class ITEM, class TAG>
OpSet< TAG > TDBDiskIndex::getTagsOfItem ( const ITEM &  item  )  const [protected, virtual]

Get the tags attached to an item.

Parameters:
item The item to query
Returns:
The set of tags, or an empty set if the item has no tags or it does not exist.

Implements Tagcoll::ReadonlyCollection< ITEM, TAG >.

template<class ITEM, class TAG>
bool TDBDiskIndex::hasTag ( const TAG &  tag  )  const [virtual]

Check if the collection contains a tag.

Parameters:
tag The tag to look for
Returns:
true if the collection contains tag, false otherwise

Reimplemented from Tagcoll::ReadonlyCollection< ITEM, TAG >.

template<class ITEM, class TAG>
OpSet< ITEM > TDBDiskIndex::getTaggedItems (  )  const [virtual]

Get the set of all the items that have tags according to this collection.

Implements Tagcoll::ReadonlyCollection< ITEM, TAG >.

template<class ITEM, class TAG>
OpSet< TAG > TDBDiskIndex::getAllTags (  )  const [virtual]

Get the set of all the tags in this collection.

Implements Tagcoll::ReadonlyCollection< ITEM, TAG >.

template<class ITEM, class TAG>
int TDBDiskIndex::getCardinality ( const TAG &  tag  )  const [virtual]

Get the cardinality of tag `tag' (that is, the number of items who have it).

Reimplemented from Tagcoll::ReadonlyCollection< ITEM, TAG >.

template<class ITEM, class TAG>
void TDBDiskIndex::output ( Consumer< ITEM, TAG > &  consumer  )  const [virtual]

Output all the contents of the collection to a Consumer.

Implements Tagcoll::ReadonlyCollection< ITEM, TAG >.

template<class ITEM, class TAG>
void TDBDiskIndex::applyChange ( const PatchList< ITEM, TAG > &  change  )  [virtual]

Apply a patch to the collection.

Example:

 void perform(const PatchList<ITEM, TAG>& change)
 {
    collection.applyChange(change);
    undo.push_back(change.getReverse());
 }

Implements Tagcoll::Collection< ITEM, TAG >.

template<>
OpSet< string > Tagcoll::TDBDiskIndex< string, string >::getItemsHavingTag ( const string &  tag  )  const

template<>
OpSet< string > Tagcoll::TDBDiskIndex< string, string >::getTagsOfItem ( const string &  item  )  const


Member Data Documentation

template<class ITEM, class TAG>
TDBFile Tagcoll::TDBDiskIndex< ITEM, TAG >::pkgdb [protected]

template<class ITEM, class TAG>
TDBFile Tagcoll::TDBDiskIndex< ITEM, TAG >::tagdb [protected]

template<class ITEM, class TAG>
const Converter<ITEM, std::string>& Tagcoll::TDBDiskIndex< ITEM, TAG >::fromitem [protected]

template<class ITEM, class TAG>
const Converter<TAG, std::string>& Tagcoll::TDBDiskIndex< ITEM, TAG >::fromtag [protected]

template<class ITEM, class TAG>
const Converter<std::string, ITEM>& Tagcoll::TDBDiskIndex< ITEM, TAG >::toitem [protected]

template<class ITEM, class TAG>
const Converter<std::string, TAG>& Tagcoll::TDBDiskIndex< ITEM, TAG >::totag [protected]


The documentation for this class was generated from the following files:
Generated on Sat Jan 17 03:54:46 2009 for libtagcoll by  doxygen 1.5.1