00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef PHASHING_H
00021 #define PHASHING_H
00022
00023 #include <string>
00024 #include <vector>
00025 #include <ext/hash_set>
00026 #include <ext/hash_map>
00027 #include <math3d/primitives.h>
00028
00029 using namespace std;
00030 using namespace __gnu_cxx;
00031
00032 typedef pair<string,string> StringPair;
00033
00034 class PAtom;
00035 class PBond;
00036
00037 struct vectorHash {
00038 public:
00039 size_t operator()(const Vector3 &v) const
00040 {
00041 hash<int> intHash;
00042 int x = int(v.x) + 101, y = int(v.y) + 201, z = int(v.z) + 301;
00043 return intHash(x * y * z);
00044 }
00045 };
00046
00047 struct vectorEq {
00048 public:
00049 bool operator()(const Vector3 &v1, const Vector3 &v2) const
00050 {
00051 return(v1 == v2);
00052 }
00053 };
00054
00055 struct vectorPointerHash {
00056 public:
00057 size_t operator()(const Vector3 *v) const
00058 {
00059 hash<size_t> h;
00060 size_t vectorPtr = (size_t) v;
00061 return h(vectorPtr);
00062 }
00063 };
00064
00065 struct vectorPointerEq {
00066 public:
00067 bool operator()(const Vector3 *v1, const Vector3 *v2) const
00068 {
00069 return (v1 == v2);
00070 }
00071 };
00072
00073 class stringHasher {
00074 public:
00075 size_t operator()(string const &str) const
00076 {
00077 hash<char const *> h;
00078 return (h(str.c_str()));
00079 }
00080 };
00081
00082 struct eqString
00083 {
00084 bool operator()(string s1, string s2) const
00085 {
00086 return(s1 == s2);
00087 }
00088 };
00089
00090
00091 class stringPairHasher {
00092 public:
00093 size_t operator()(StringPair const &s) const
00094 {
00095 stringHasher h;
00096 return (h(s.first+s.second));
00097 }
00098 };
00099
00100 struct eqStringPairExclusive
00101 {
00102 bool operator()(const StringPair &s1, const StringPair &s2) const
00103 {
00104 return s1.first == s2.first && s1.second == s2.second;
00105 }
00106
00107 };
00108
00109 struct eqStringPairEither
00110 {
00111 bool operator()(const StringPair &s1, const StringPair &s2) const
00112 {
00113 if (s1.first == s2.first) return s1.second == s2.second;
00114 else if (s1.first == s2.second) return s1.second==s2.first;
00115 else return false;
00116 }
00117
00118 };
00119
00120
00121
00122
00123
00124 struct pairAtomHash {
00125 public:
00126 size_t operator()(const pair<PAtom *,PAtom *> a) const {
00127 return (size_t) a.first + (size_t) a.second;
00128 }
00129 };
00130
00131 struct pairAtomEq {
00132 public:
00133 bool operator()(const pair<PAtom *,PAtom *> a1, const pair<PAtom *,PAtom *> a2) const {
00134 return (a1.first == a2.first) && a1.second == a2.second ||
00135 a1.first==a2.second && a1.second == a2.first;
00136 }
00137 };
00138
00139 struct atomHash {
00140 public:
00141 size_t operator()(const PAtom *a) const {
00142 hash<size_t> h;
00143 size_t atomPtr = (size_t) a;
00144 return h(atomPtr);
00145 }
00146 };
00147
00148 struct atomEq {
00149 public:
00150 bool operator()(const PAtom *a1, const PAtom *a2) const {
00151 return (a1 == a2);
00152 }
00153 };
00154
00155
00156
00157
00158
00159
00160 typedef hash_set<PAtom*, atomHash, atomEq> AtomSet;
00161 typedef hash_set<const PAtom *, atomHash, atomEq> ConstAtomSet;
00162 typedef hash_set<const Vector3 *, vectorPointerHash, vectorPointerEq> ConstVectorSet;
00163
00164 typedef hash_set<pair<PAtom *, PAtom *>, pairAtomHash, pairAtomEq> AtomCollisions;
00165 typedef hash_map<pair<PAtom *, PAtom *>, int, pairAtomHash, pairAtomEq> AtomSeparations;
00166 typedef hash_map<Vector3, AtomSet, vectorHash, vectorEq> CollisionMap;
00167 typedef hash_map<Vector3, bool, vectorHash, vectorEq> OccupancyMap;
00168
00169
00170
00171
00172 #define HASH_MAP_STR(t) hash_map<string, t, stringHasher, eqString>
00173 #define HASH_MAP_STRPAIR_EX(t) hash_map<StringPair, t, stringPairHasher, eqStringPairExclusive>
00174 #define HASH_MAP_STRPAIR_OR(t) hash_map<StringPair, t, stringPairHasher, eqStringPairEither>
00175
00176
00177 typedef HASH_MAP_STR(vector<PBond *>) DOF_Cache;
00178 typedef HASH_MAP_STR(vector<PAtom *>) Atom_Cache;
00179 typedef HASH_MAP_STR(Vector3) AtomPositions;
00180 typedef HASH_MAP_STR(string) StringMap;
00181 typedef HASH_MAP_STRPAIR_OR(PBond *) ID_To_DOF_Map;
00182
00183
00184 #endif