IntDiskIndex.h

Go to the documentation of this file.
00001 #ifndef TAGCOLL_INT_DISK_INDEX_H
00002 #define TAGCOLL_INT_DISK_INDEX_H
00003 
00008 /*
00009  * Copyright (C) 2006  Enrico Zini <enrico@debian.org>
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00024  */
00025 
00026 #include <tagcoll/Collection.h>
00027 #include <tagcoll/Serializer.h>
00028 #include <tagcoll/Exception.h>
00029 #include <tagcoll/IntIndex.h>
00030 
00031 namespace Tagcoll
00032 {
00033 
00046 template<class ITEM, class TAG>
00047 class IntDiskIndex : public ReadonlyCollection<ITEM, TAG>
00048 {
00049 protected:
00050     IntIndex pkgidx;
00051     IntIndex tagidx;
00052     const Converter<ITEM, int>* m_fromitem;
00053     const Converter<TAG, int>* m_fromtag;
00054     const Converter<int, ITEM>* m_toitem;
00055     const Converter<int, TAG>* m_totag;
00056 
00057     inline int fromitem(const ITEM& tag) const { return (*m_fromitem)(tag); }
00058     inline int fromtag(const TAG& tag) const { return (*m_fromtag)(tag); }
00059     inline ITEM toitem(const int& tag) const { return (*m_toitem)(tag); }
00060     inline TAG totag(const int& tag) const { return (*m_totag)(tag); }
00061 
00062     virtual OpSet<ITEM> getItemsHavingTag(const TAG& tag) const;
00063     virtual OpSet<ITEM> getItemsHavingTags(const OpSet<TAG>& tags) const;
00064     virtual OpSet<TAG> getTagsOfItem(const ITEM& item) const;
00065     virtual OpSet<TAG> getTagsOfItems(const OpSet<ITEM>& items) const;
00066 
00067 public:
00085     IntDiskIndex()
00086         :   m_fromitem(0), m_fromtag(0), m_toitem(0), m_totag(0) {}
00087     IntDiskIndex(
00088             const MasterMMapIndex& master,
00089             int pkgindex, int tagindex,
00090             const Converter<ITEM, int>* fromitem,
00091             const Converter<TAG, int>* fromtag,
00092             const Converter<int, ITEM>* toitem,
00093             const Converter<int, TAG>* totag)
00094         :   pkgidx(master, pkgindex), tagidx(master, tagindex),
00095             m_fromitem(fromitem), m_fromtag(fromtag),
00096             m_toitem(toitem), m_totag(totag) {}
00097     virtual ~IntDiskIndex() {}
00098 
00099     void init(const MasterMMapIndex& master, int pkgindex, int tagindex,
00100             const Converter<ITEM, int>* fromitem,
00101             const Converter<TAG, int>* fromtag,
00102             const Converter<int, ITEM>* toitem,
00103             const Converter<int, TAG>* totag)
00104     {
00105         m_fromitem = fromitem;
00106         m_fromtag = fromtag;
00107         m_toitem = toitem;
00108         m_totag = totag;
00109         pkgidx.init(master, pkgindex);
00110         tagidx.init(master, tagindex);
00111     }
00112 
00113     void init(const MasterMMapIndex& master, int pkgindex, int tagindex)
00114     {
00115         pkgidx.init(master, pkgindex);
00116         tagidx.init(master, tagindex);
00117     }
00118 
00119     virtual bool hasTag(const TAG& tag) const
00120     {
00121         return tagidx.size(fromtag(tag)) > 0;
00122     }
00123 
00124     virtual OpSet<ITEM> getTaggedItems() const;
00125 
00126     virtual OpSet<TAG> getAllTags() const;
00127 
00128     virtual int getCardinality(const TAG& tag) const
00129     {
00130         return tagidx.size(fromtag(tag));
00131     }
00132 
00133     virtual OpSet<TAG> getCompanionTags(const OpSet<TAG>& tags) const;
00134 
00135     virtual void output(Consumer<ITEM, TAG>& consumer) const;
00136 };
00137 
00138 template<class ITEM, class TAG>
00139 class IntDiskIndexer : public Consumer<ITEM, TAG>
00140 {
00141 protected:
00142     IntIndexer pkgidx;
00143     IntIndexer tagidx;
00144     const Converter<ITEM, int>& fromitem;
00145     const Converter<TAG, int>& fromtag;
00146 
00147     virtual void consumeItemUntagged(const ITEM&) {}
00148     virtual void consumeItem(const ITEM& item, const OpSet<TAG>& tags);
00149 
00150 public:
00151     IntDiskIndexer(
00152             const Converter<ITEM, int>& fromitem,
00153             const Converter<TAG, int>& fromtag);
00154     virtual ~IntDiskIndexer() {}
00155 
00156     const MMapIndexer& pkgIndexer() const { return pkgidx; }
00157     const MMapIndexer& tagIndexer() const { return tagidx; }
00158 };
00159 
00160 
00161 };
00162 
00163 // vim:set ts=4 sw=4:
00164 #endif

Generated on Sat Jan 17 04:23:32 2009 for libtagcoll by  doxygen 1.5.1