aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-24 00:04:09 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2006-02-24 00:04:09 +0000
commitf938db7fcc47a5cdd8b20b6cb2f9870eea1134af (patch)
treed41746bb584f73326235946851b6d3590b2a89e3
parent2b91af3ea9a66285642d0a88ee2a9ec0c75bddff (diff)
downloadpaludis-f938db7fcc47a5cdd8b20b6cb2f9870eea1134af.tar.gz
paludis-f938db7fcc47a5cdd8b20b6cb2f9870eea1134af.tar.xz
Use a hashed container for digest lookups
-rw-r--r--paludis/hashed_containers.cc16
-rw-r--r--paludis/hashed_containers.hh.in27
-rw-r--r--paludis/qa/digest_collisions_check.cc5
3 files changed, 46 insertions, 2 deletions
diff --git a/paludis/hashed_containers.cc b/paludis/hashed_containers.cc
index ffaa618..8d29550 100644
--- a/paludis/hashed_containers.cc
+++ b/paludis/hashed_containers.cc
@@ -49,6 +49,22 @@ CRCHash<QualifiedPackageName>::operator() (const QualifiedPackageName & val) con
}
std::size_t
+CRCHash<std::string>::operator() (const std::string & val) const
+{
+ std::size_t h(0);
+
+ for (std::string::size_type t(0) ; t < val.length() ; ++t)
+ {
+ std::size_t hh(h & h_mask);
+ h <<= 5;
+ h ^= (hh >> h_shift);
+ h ^= val[t];
+ }
+
+ return h;
+}
+
+std::size_t
CRCHash<std::pair<QualifiedPackageName, VersionSpec> >::operator() (
const std::pair<QualifiedPackageName, VersionSpec> & val) const
{
diff --git a/paludis/hashed_containers.hh.in b/paludis/hashed_containers.hh.in
index 5b82282..1c7c6ae 100644
--- a/paludis/hashed_containers.hh.in
+++ b/paludis/hashed_containers.hh.in
@@ -170,6 +170,33 @@ namespace paludis
#endif
};
+
+ /**
+ * Hash, for a string.
+ */
+ template<>
+ class CRCHash<std::string> :
+ public std::unary_function<std::string, std::size_t>,
+ protected CRCHashBase
+ {
+ public:
+ /// Hash function.
+ std::size_t operator() (const std::string & val) const;
+
+#if (! PALUDIS_HAVE_TR1_HASHES) && (! PALUDIS_HAVE_EXT_HASHES)
+ enum
+ {
+ min_buckets = 32,
+ bucket_size = 4
+ };
+
+ bool operator() (const std::string & i1, const std::string & i2) const
+ {
+ return i1 < i2;
+ }
+#endif
+ };
+
/**
* Hash, for a QualifiedPackageName + VersionSpec pair.
*/
diff --git a/paludis/qa/digest_collisions_check.cc b/paludis/qa/digest_collisions_check.cc
index 3fe790b..89daf41 100644
--- a/paludis/qa/digest_collisions_check.cc
+++ b/paludis/qa/digest_collisions_check.cc
@@ -22,6 +22,7 @@
#include <paludis/dir_iterator.hh>
#include <paludis/smart_record.hh>
#include <paludis/tokeniser.hh>
+#include <paludis/hashed_containers.hh>
#include <map>
#include <fstream>
@@ -46,7 +47,7 @@ namespace
typedef MakeSmartRecord<DigestDataTag>::Type DigestData;
- static std::map<std::string, DigestData> digests;
+ static MakeHashedMap<std::string, DigestData>::Type digests;
}
DigestCollisionsCheck::DigestCollisionsCheck()
@@ -77,7 +78,7 @@ DigestCollisionsCheck::operator() (const FSEntry & d) const
if ("MD5" != entries.at(0))
continue;
- std::map<std::string, DigestData>::iterator existing(
+ MakeHashedMap<std::string, DigestData>::Type::iterator existing(
digests.find(entries.at(2)));
if (digests.end() != existing)
{