00001 #ifndef VTS_SQ_ID_HPP
00002 #define VTS_SQ_ID_HPP
00003
00004 #include "../Common.h"
00005
00006 #include <algorithm>
00007 #include <ostream>
00008
00009 #include "SuperFastHash.h"
00010 #include <boost/config.hpp>
00011
00014
00020 #ifdef _MSC_VER
00021
00022 template<int TLength>
00023 class VtsSqId;
00024
00025 template<>
00026 class VtsSqId<0> {};
00027
00028 #endif
00029
00030 template<int TLength>
00031 class VtsSqId
00032 {
00033 uTind v[TLength];
00034 public:
00035 static const int length=TLength;
00036 VtsSqId(const uTind vts[])
00037 {
00038 memcpy(v,vts,sizeof(uTind)*TLength);
00039 std::sort(v,v+TLength);
00040 }
00041
00042 VtsSqId(const VtsSqId & other)
00043 {
00044 memcpy(v,other.v,sizeof(uTind)*TLength);
00045 }
00046
00048 VtsSqId& operator=(const VtsSqId & other)
00049 {
00050 memcpy(v,other.v, sizeof(uTind)*TLength);
00051 return *this;
00052 }
00053
00054 inline bool operator==(const VtsSqId & other) const
00055 {
00056 bool eq(true);
00057 for(int i(0); (i < TLength) && eq; ++i) {
00058 if(v[i] != other.v[i]){
00059 eq=false;
00060 }
00061 }
00062 return eq;
00063 }
00064
00065 inline bool operator!=(const VtsSqId & other) const
00066 {
00067 return !(*this==other);
00068 }
00069
00070 inline bool operator<(const VtsSqId & other) const
00071 {
00072 register int i(0);
00073 while((v[i]==other.v[i]) && (i < TLength-1) ) {
00074 ++i;
00075 }
00076 return v[i] < other.v[i];
00077 }
00078
00079 inline bool operator>=(const VtsSqId & other) const
00080 {
00081 return ! ( this->operator<(other) );
00082 }
00083
00084 inline bool operator>(const VtsSqId & other) const
00085 {
00086 register int i(0);
00087 while((v[i]==other.v[i]) && (i < TLength-1) ) {
00088 ++i;
00089 }
00090 return v[i] > other.v[i];
00091 }
00092
00093 inline bool operator<=(const VtsSqId & other) const
00094 {
00095 return ! ( this->operator>(other) );
00096 }
00097
00098
00099
00100 template<int T>
00101 friend std::ostream & operator<<(std::ostream & os,const VtsSqId<T> & id);
00102
00103 };
00104 template<int T>
00105 std::ostream & operator<<(std::ostream & os,const VtsSqId<T> & id)
00106 {
00107 for(int i(0); i < VtsSqId<T>::length; ++i) {
00108 os << id.v[i] << " ";
00109 }
00110 return os;
00111 }
00112
00117 #ifdef BOOST_NO_CXX11_HDR_UNORDERED_MAP
00118 #include <boost/unordered/unordered_map.hpp>
00119
00120 namespace boost {
00121
00122 template<int T>
00123 struct hash<VtsSqId <T> >
00124 {
00125 typedef VtsSqId <T> argument_type;
00126 typedef size_t result_type;
00127
00128 result_type operator () (const argument_type& x) const {
00129 return SuperFastHash( reinterpret_cast<const char*>(&x),sizeof(x));
00130 }
00131 };
00132
00133 }
00134
00135 using boost::unordered::unordered_map;
00136 #else
00137 #include <unordered_map>
00139 namespace std {
00140
00141 template<int T>
00142 struct hash<VtsSqId <T>>
00143 {
00144 typedef VtsSqId <T> argument_type;
00145 typedef size_t result_type;
00146
00147 result_type operator () (const argument_type& x) const {
00148 return SuperFastHash( reinterpret_cast<const char*>(&x),sizeof(x));
00149 }
00150 };
00151
00152 template<int T>
00153 struct __is_fast_hash< hash< VtsSqId <T> > > : public std::false_type
00154 { };
00155
00156 }
00157
00158 using std::unordered_map;
00159
00160 #endif
00161
00162 #endif //guard header