IntIndex.h

Go to the documentation of this file.
00001 #ifndef TAGCOLL_INT_INDEX_H
00002 #define TAGCOLL_INT_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/Exception.h>
00027 #include <tagcoll/MMapIndex.h>
00028 #include <vector>
00029 #include <set>
00030 
00031 namespace Tagcoll
00032 {
00033 
00051 class IntIndex : public MMapIndex
00052 {
00053 protected:
00054     inline int* buf() const { return (int*)m_buf; }
00055     inline size_t ofs(int val) const { return buf()[val]; }
00056 
00057 public:
00058     IntIndex() {}
00059     IntIndex(const MasterMMapIndex& master, int idx) : MMapIndex(master, idx) {}
00060 
00061     const int* data(int val) const { return (val >= 0 && (unsigned)val < size()) ? buf() + ofs(val) + 1 : 0; }
00062     size_t size(int val) const { return (val >= 0 && (unsigned)val < size()) ? buf()[ofs(val)] : 0; }
00063     size_t size() const { return ofs(0); }
00064 };
00065 
00069 class IntIndexer : public MMapIndexer, public std::vector<std::set<int> >
00070 {
00071 public:
00073     void map(unsigned int key, int val)
00074     {
00075         if (size() <= key)
00076             resize(key + 1);
00077         (*this)[key].insert(val);
00078     }
00079     
00081     virtual int encodedSize() const;
00082 
00085     virtual void encode(char* buf) const;
00086 };
00087 
00088 };
00089 
00090 // vim:set ts=4 sw=4:
00091 #endif

Generated on Wed Jun 20 19:14:21 2007 for libtagcoll by  doxygen 1.5.2