Simple Application Framework  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Saf/Collection/HashSet.h
Go to the documentation of this file.
00001 /*
00002     This file is part of Simple Application Framework (Saf) library.
00003     Copyright (C) 2010 - 2012 Ondrej Danek <ondrej.danek@gmail.com>
00004 
00005     This library is free software: you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published 
00007     by the Free Software Foundation, either version 3 of the License, or
00008     (at your option) any later version.
00009 
00010     Saf is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with Simple Application Framework library. If not, 
00017     see <http://www.gnu.org/licenses/>.
00018 */
00019 
00028 #ifndef SAF_COLLECTION_HASHSET_H
00029 #define SAF_COLLECTION_HASHSET_H
00030 
00031 #include "../Algo/Hash.h"
00032 #include "../Algo/Struct/HashTable.h"
00033 #include "../Algo/Struct/HashTablePolicy.h"
00034 #include "../Algo/Predicate.h"
00035 #include "../Algo/Basic.h"
00036 
00037 namespace Saf
00038 {
00039     namespace Collection
00040     {
00061         template <class ValType, class HashFuncType = Algo::Hash<ValType>, 
00062             class HashPolicyType = Algo::Struct::HashPolicy::PrimePolicy,
00063             class CompType = Algo::Predicate::Equal<ValType> > 
00064         class HashSet
00065             : public Algo::Struct::HashTable<ValType,ValType,Algo::Identity<ValType>,HashFuncType,HashPolicyType,CompType>
00066         {
00067         protected:
00068             typedef Algo::Struct::HashTable<ValType,ValType,Algo::Identity<ValType>,HashFuncType,HashPolicyType,CompType> BaseType;
00069             typedef HashSet<ValType,HashFuncType,HashPolicyType,CompType> MyType;
00070 
00071         public:
00078             explicit HashSet(Size bucketHint = 0)
00079                 : BaseType(bucketHint)
00080             {}
00081 
00083             HashSet(const MyType& hs) 
00084                 : BaseType(hs)
00085             {}
00086 
00088             MyType& operator=(const MyType& hs)
00089             {
00090                 BaseType::operator=(hs);
00091                 return *this;
00092             }
00093 
00099             MyType& Swap(MyType& hs)
00100             {
00101                 BaseType::Swap(hs);
00102                 return *this;
00103             }
00104         };
00105     }
00106 
00108     namespace Algo
00109     {
00110         // Swap specialization for hash set container.
00111         template <class ValType, class HashFuncType, class HashPolicyType, class CompType>
00112         struct SwapFunc< Collection::HashSet<ValType,HashFuncType,HashPolicyType,CompType> >
00113         {
00114             void operator()(Collection::HashSet<ValType,HashFuncType,HashPolicyType,CompType>& x, 
00115                 Collection::HashSet<ValType,HashFuncType,HashPolicyType,CompType>& y)
00116             {
00117                 x.Swap(y);
00118             }
00119         };
00120     }
00122 }
00123 
00124 #endif