* prefer HashSet and HashMap to respective std-classes where possible
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40518 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2011, Oliver Tappe <[email protected]>
|
||||||
|
* Distributed under the terms of the MIT License.
|
||||||
|
*/
|
||||||
|
#ifndef _PACKAGE__PRIVATE__HASHABLE_STRING_H_
|
||||||
|
#define _PACKAGE__PRIVATE__HASHABLE_STRING_H_
|
||||||
|
|
||||||
|
|
||||||
|
#include <String.h>
|
||||||
|
|
||||||
|
#include <HashString.h>
|
||||||
|
|
||||||
|
|
||||||
|
namespace BPackageKit {
|
||||||
|
|
||||||
|
namespace BPrivate {
|
||||||
|
|
||||||
|
|
||||||
|
class HashableString : public BString {
|
||||||
|
public:
|
||||||
|
inline HashableString();
|
||||||
|
|
||||||
|
inline HashableString(const BString& string);
|
||||||
|
|
||||||
|
inline uint32 GetHashCode() const;
|
||||||
|
|
||||||
|
inline bool operator!= (const HashableString& other) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
uint32 fHashCode;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
inline
|
||||||
|
HashableString::HashableString()
|
||||||
|
:
|
||||||
|
fHashCode(0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline
|
||||||
|
HashableString::HashableString(const BString& string)
|
||||||
|
:
|
||||||
|
BString(string),
|
||||||
|
fHashCode(string_hash(String()))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline uint32
|
||||||
|
HashableString::GetHashCode() const
|
||||||
|
{
|
||||||
|
return fHashCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline bool
|
||||||
|
HashableString::operator!= (const HashableString& other) const
|
||||||
|
{
|
||||||
|
return Compare(other) != 0 || fHashCode != other.fHashCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace BPrivate
|
||||||
|
|
||||||
|
} // namespace BPackageKit
|
||||||
|
|
||||||
|
|
||||||
|
#endif // _PACKAGE__PRIVATE__HASHABLE_STRING_H_
|
||||||
@@ -19,12 +19,12 @@
|
|||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
|
|
||||||
#include <HashMap.h>
|
#include <HashMap.h>
|
||||||
#include <HashString.h>
|
|
||||||
|
|
||||||
#include <package/hpkg/ErrorOutput.h>
|
#include <package/hpkg/ErrorOutput.h>
|
||||||
#include <package/hpkg/PackageInfoAttributeValue.h>
|
#include <package/hpkg/PackageInfoAttributeValue.h>
|
||||||
#include <package/hpkg/RepositoryContentHandler.h>
|
#include <package/hpkg/RepositoryContentHandler.h>
|
||||||
#include <package/hpkg/RepositoryReader.h>
|
#include <package/hpkg/RepositoryReader.h>
|
||||||
|
#include <package/HashableString.h>
|
||||||
#include <package/PackageInfo.h>
|
#include <package/PackageInfo.h>
|
||||||
#include <package/RepositoryInfo.h>
|
#include <package/RepositoryInfo.h>
|
||||||
|
|
||||||
@@ -32,40 +32,13 @@
|
|||||||
namespace BPackageKit {
|
namespace BPackageKit {
|
||||||
|
|
||||||
|
|
||||||
|
using BPrivate::HashableString;
|
||||||
using namespace BHPKG;
|
using namespace BHPKG;
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
|
||||||
struct HashableString : public BString {
|
|
||||||
uint32 hashCode;
|
|
||||||
|
|
||||||
HashableString()
|
|
||||||
:
|
|
||||||
hashCode(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
HashableString(const BString& string_)
|
|
||||||
:
|
|
||||||
BString(string_),
|
|
||||||
hashCode(string_hash(String()))
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
inline uint32 GetHashCode() const
|
|
||||||
{
|
|
||||||
return hashCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool operator!= (const HashableString& other) const
|
|
||||||
{
|
|
||||||
return Compare(other) != 0 || hashCode != other.hashCode;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
typedef ::BPrivate::HashMap<HashableString, BPackageInfo> PackageHashMap;
|
typedef ::BPrivate::HashMap<HashableString, BPackageInfo> PackageHashMap;
|
||||||
|
|
||||||
struct RepositoryContentHandler : BRepositoryContentHandler {
|
struct RepositoryContentHandler : BRepositoryContentHandler {
|
||||||
|
|||||||
@@ -8,13 +8,13 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <new>
|
#include <new>
|
||||||
#include <set>
|
|
||||||
|
|
||||||
#include <ByteOrder.h>
|
#include <ByteOrder.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <Path.h>
|
#include <Path.h>
|
||||||
|
|
||||||
#include <AutoDeleter.h>
|
#include <AutoDeleter.h>
|
||||||
|
#include <HashSet.h>
|
||||||
|
|
||||||
#include <package/hpkg/HPKGDefsPrivate.h>
|
#include <package/hpkg/HPKGDefsPrivate.h>
|
||||||
#include <package/hpkg/PackageDataReader.h>
|
#include <package/hpkg/PackageDataReader.h>
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
#include <package/hpkg/PackageReader.h>
|
#include <package/hpkg/PackageReader.h>
|
||||||
#include <package/BlockBufferCacheNoLock.h>
|
#include <package/BlockBufferCacheNoLock.h>
|
||||||
#include <package/ChecksumAccessors.h>
|
#include <package/ChecksumAccessors.h>
|
||||||
|
#include <package/HashableString.h>
|
||||||
#include <package/RepositoryInfo.h>
|
#include <package/RepositoryInfo.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -34,6 +35,7 @@ namespace BPrivate {
|
|||||||
|
|
||||||
|
|
||||||
using BPackageKit::BPrivate::GeneralFileChecksumAccessor;
|
using BPackageKit::BPrivate::GeneralFileChecksumAccessor;
|
||||||
|
using BPackageKit::BPrivate::HashableString;
|
||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@@ -254,7 +256,8 @@ private:
|
|||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
|
|
||||||
struct RepositoryWriterImpl::PackageNameSet : public std::set<BString> {
|
struct RepositoryWriterImpl::PackageNameSet
|
||||||
|
: public ::BPrivate::HashSet<HashableString> {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -281,6 +284,9 @@ RepositoryWriterImpl::Init(const char* fileName)
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
fPackageNames = new PackageNameSet();
|
fPackageNames = new PackageNameSet();
|
||||||
|
status_t result = fPackageNames->InitCheck();
|
||||||
|
if (result != B_OK)
|
||||||
|
return result;
|
||||||
return _Init(fileName);
|
return _Init(fileName);
|
||||||
} catch (status_t error) {
|
} catch (status_t error) {
|
||||||
return error;
|
return error;
|
||||||
@@ -417,9 +423,7 @@ RepositoryWriterImpl::_RegisterCurrentPackageInfo()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// reject package with a name that we've seen already
|
// reject package with a name that we've seen already
|
||||||
PackageNameSet::const_iterator namePos
|
if (fPackageNames->Contains(fPackageInfo.Name())) {
|
||||||
= fPackageNames->find(fPackageInfo.Name());
|
|
||||||
if (namePos != fPackageNames->end()) {
|
|
||||||
fListener->PrintError("package %s has already been added!\n",
|
fListener->PrintError("package %s has already been added!\n",
|
||||||
fPackageInfo.Name().String());
|
fPackageInfo.Name().String());
|
||||||
return B_NAME_IN_USE;
|
return B_NAME_IN_USE;
|
||||||
@@ -449,7 +453,8 @@ RepositoryWriterImpl::_RegisterCurrentPackageInfo()
|
|||||||
return B_BAD_DATA;
|
return B_BAD_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
fPackageNames->insert(fPackageInfo.Name());
|
if ((result = fPackageNames->Add(fPackageInfo.Name())) != B_OK)
|
||||||
|
return result;
|
||||||
|
|
||||||
RegisterPackageInfo(PackageAttributes(), fPackageInfo);
|
RegisterPackageInfo(PackageAttributes(), fPackageInfo);
|
||||||
fPackageCount++;
|
fPackageCount++;
|
||||||
|
|||||||
Reference in New Issue
Block a user