Sieve.h

Go to the documentation of this file.
00001 /*
00002 * Copyright (C) 2007-2008 Anael Orlinski
00003 *
00004 * This file is part of Panomatic.
00005 *
00006 * Panomatic is free software; you can redistribute it and/or modify
00007 * it under the terms of the GNU General Public License as published by
00008 * the Free Software Foundation; either version 2 of the License, or
00009 * (at your option) any later version.
00010 *
00011 * Panomatic is distributed in the hope that it will be useful,
00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 * GNU General Public License for more details.
00015 *
00016 * You should have received a copy of the GNU General Public License
00017 * along with Panomatic; if not, write to the Free Software
00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 */
00020 
00021 #ifndef __lfeat_sieve_h
00022 #define __lfeat_sieve_h
00023 
00024 #include "BoundedSet.h"
00025 
00026 namespace lfeat
00027 {
00028 
00029 template <typename _Key>
00030 class SieveExtractor
00031 {
00032 public:
00033     virtual void operator()(const _Key& k) = 0;
00034 };
00035 
00036 template <typename _Key, typename _Compare = std::less<_Key> >
00037 class Sieve
00038 {
00039 
00040 public:
00041     Sieve(int iWidth, int iHeight, int iLength);
00042     void insert(_Key& iElem, int iWidth, int iHeight);
00043 
00044     // extract
00045     void extract(SieveExtractor<_Key>& iEx);
00046 
00047 private:
00048     std::vector<lfeat::bounded_set< _Key, _Compare > > _buckets;
00049     int _width, _height;
00050 
00051 
00052 };
00053 
00054 template <typename _Key, typename _Compare>
00055 Sieve<_Key, _Compare>::Sieve(int iWidth, int iHeight, int iLength) :
00056     _buckets(std::vector<bounded_set< _Key, _Compare > >(iWidth* iHeight)),
00057     _width(iWidth), _height(iHeight)
00058 {
00059     typename std::vector<bounded_set< _Key, _Compare > >::iterator aVB, aVE;
00060     aVB = _buckets.begin();
00061     aVE = _buckets.end();
00062     for (; aVB != aVE; ++aVB)
00063     {
00064         aVB->setMaxSize(iLength);
00065     }
00066 }
00067 
00068 template <typename _Key, typename _Compare>
00069 void Sieve<_Key, _Compare>::insert(_Key& iElem, int iWidth, int iHeight)
00070 {
00071     _buckets[iWidth * _height + iHeight].insert(iElem);
00072 }
00073 
00074 template <typename _Key, typename _Compare>
00075 void Sieve<_Key, _Compare>::extract(SieveExtractor<_Key>& iEx)
00076 {
00077     typename std::vector<bounded_set< _Key, _Compare > >::iterator aVB, aVE;
00078     aVB = _buckets.begin();
00079     aVE = _buckets.end();
00080     for (; aVB != aVE; ++aVB)
00081     {
00082         typename std::set<_Key, _Compare>::iterator aSB, aSE;
00083         std::set<_Key, _Compare>& aS = aVB->getSet();
00084         aSB = aS.begin();
00085         aSE = aS.end();
00086         for (; aSB != aSE; ++aSB)
00087         {
00088             iEx(*aSB);
00089         }
00090     }
00091 }
00092 
00093 }
00094 
00095 #endif // __lfeat_sieve_h

Generated on 24 Nov 2014 for Hugintrunk by  doxygen 1.4.7