mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-12-28 03:37:59 +00:00
STYLE: simplify hashing to use struct instead of class
- more consistent with STL practices for function classes. - string::hash function class now operates on std::string rather than Foam::string since we have now avoided inadvertent use of string conversion from int in more places.
This commit is contained in:
@ -62,15 +62,8 @@ public:
|
||||
{
|
||||
public:
|
||||
|
||||
class hash
|
||||
:
|
||||
public Hash<interfacePair>
|
||||
struct hash
|
||||
{
|
||||
public:
|
||||
|
||||
hash()
|
||||
{}
|
||||
|
||||
label operator()(const interfacePair& key) const
|
||||
{
|
||||
return word::hash()(key.first()) + word::hash()(key.second());
|
||||
@ -80,8 +73,7 @@ public:
|
||||
|
||||
// Constructors
|
||||
|
||||
interfacePair()
|
||||
{}
|
||||
interfacePair() {} // = default
|
||||
|
||||
interfacePair(const word& alpha1Name, const word& alpha2Name)
|
||||
:
|
||||
|
||||
@ -74,30 +74,16 @@ public:
|
||||
{
|
||||
public:
|
||||
|
||||
class symmHash
|
||||
:
|
||||
public Hash<interfacePair>
|
||||
struct symmHash
|
||||
{
|
||||
public:
|
||||
|
||||
symmHash()
|
||||
{}
|
||||
|
||||
label operator()(const interfacePair& key) const
|
||||
{
|
||||
return word::hash()(key.first()) + word::hash()(key.second());
|
||||
}
|
||||
};
|
||||
|
||||
class hash
|
||||
:
|
||||
public Hash<interfacePair>
|
||||
struct hash
|
||||
{
|
||||
public:
|
||||
|
||||
hash()
|
||||
{}
|
||||
|
||||
label operator()(const interfacePair& key) const
|
||||
{
|
||||
return word::hash()(key.first(), word::hash()(key.second()));
|
||||
@ -107,8 +93,7 @@ public:
|
||||
|
||||
// Constructors
|
||||
|
||||
interfacePair()
|
||||
{}
|
||||
interfacePair() {} // = default
|
||||
|
||||
interfacePair(const word& alpha1Name, const word& alpha2Name)
|
||||
:
|
||||
@ -233,8 +218,7 @@ public:
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~multiphaseSystem()
|
||||
{}
|
||||
virtual ~multiphaseSystem() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
@ -71,15 +71,8 @@ public:
|
||||
{
|
||||
public:
|
||||
|
||||
class hash
|
||||
:
|
||||
public Hash<interfacePair>
|
||||
struct hash
|
||||
{
|
||||
public:
|
||||
|
||||
hash()
|
||||
{}
|
||||
|
||||
label operator()(const interfacePair& key) const
|
||||
{
|
||||
return word::hash()(key.first()) + word::hash()(key.second());
|
||||
@ -89,8 +82,7 @@ public:
|
||||
|
||||
// Constructors
|
||||
|
||||
interfacePair()
|
||||
{}
|
||||
interfacePair() {} // = default
|
||||
|
||||
interfacePair(const word& alpha1Name, const word& alpha2Name)
|
||||
:
|
||||
@ -196,8 +188,7 @@ public:
|
||||
|
||||
|
||||
//- Destructor
|
||||
virtual ~multiphaseMixture()
|
||||
{}
|
||||
virtual ~multiphaseMixture() = default;
|
||||
|
||||
|
||||
// Member Functions
|
||||
|
||||
@ -27,14 +27,6 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::phasePairKey::hash::hash()
|
||||
{}
|
||||
|
||||
|
||||
Foam::phasePairKey::phasePairKey()
|
||||
{}
|
||||
|
||||
|
||||
Foam::phasePairKey::phasePairKey
|
||||
(
|
||||
const word& name1,
|
||||
@ -47,12 +39,6 @@ Foam::phasePairKey::phasePairKey
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::phasePairKey::~phasePairKey()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::phasePairKey::ordered() const
|
||||
@ -94,13 +80,13 @@ bool Foam::operator==
|
||||
const phasePairKey& b
|
||||
)
|
||||
{
|
||||
const label c = Pair<word>::compare(a,b);
|
||||
const label cmp = Pair<word>::compare(a,b);
|
||||
|
||||
return
|
||||
(a.ordered_ == b.ordered_)
|
||||
&& (
|
||||
(a.ordered_ && (c == 1))
|
||||
|| (!a.ordered_ && (c != 0))
|
||||
(a.ordered_ && (cmp == 1))
|
||||
|| (!a.ordered_ && (cmp != 0))
|
||||
);
|
||||
}
|
||||
|
||||
@ -127,7 +113,7 @@ Foam::Istream& Foam::operator>>(Istream& is, phasePairKey& key)
|
||||
{
|
||||
key.ordered_ = false;
|
||||
}
|
||||
else if(temp[1] == "in")
|
||||
else if (temp[1] == "in")
|
||||
{
|
||||
key.ordered_ = true;
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
// Forward declarations
|
||||
|
||||
class phasePairKey;
|
||||
|
||||
@ -59,41 +59,24 @@ class phasePairKey
|
||||
:
|
||||
public Pair<word>
|
||||
{
|
||||
public:
|
||||
|
||||
class hash
|
||||
:
|
||||
public Hash<phasePairKey>
|
||||
{
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
// Construct null
|
||||
hash();
|
||||
|
||||
|
||||
// Member operators
|
||||
|
||||
// Generate a hash from a phase pair key
|
||||
label operator()(const phasePairKey& key) const;
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private data
|
||||
|
||||
//- Flag to indicate whether ordering is important
|
||||
bool ordered_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
struct hash
|
||||
{
|
||||
// Generate a hash from a phase pair key
|
||||
label operator()(const phasePairKey& key) const;
|
||||
};
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
phasePairKey();
|
||||
phasePairKey() {} // = default
|
||||
|
||||
//- Construct from names and the ordering flag
|
||||
phasePairKey
|
||||
@ -105,7 +88,7 @@ public:
|
||||
|
||||
|
||||
// Destructor
|
||||
virtual ~phasePairKey();
|
||||
virtual ~phasePairKey() = default;
|
||||
|
||||
|
||||
// Access
|
||||
|
||||
@ -27,14 +27,6 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::phasePairKey::hash::hash()
|
||||
{}
|
||||
|
||||
|
||||
Foam::phasePairKey::phasePairKey()
|
||||
{}
|
||||
|
||||
|
||||
Foam::phasePairKey::phasePairKey
|
||||
(
|
||||
const word& name1,
|
||||
@ -47,12 +39,6 @@ Foam::phasePairKey::phasePairKey
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::phasePairKey::~phasePairKey()
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::label Foam::phasePairKey::hash::operator()
|
||||
@ -86,13 +72,13 @@ bool Foam::operator==
|
||||
const phasePairKey& b
|
||||
)
|
||||
{
|
||||
const label c = Pair<word>::compare(a,b);
|
||||
const label cmp = Pair<word>::compare(a,b);
|
||||
|
||||
return
|
||||
(a.ordered_ == b.ordered_)
|
||||
&& (
|
||||
(a.ordered_ && (c == 1))
|
||||
|| (!a.ordered_ && (c != 0))
|
||||
(a.ordered_ && (cmp == 1))
|
||||
|| (!a.ordered_ && (cmp != 0))
|
||||
);
|
||||
}
|
||||
|
||||
@ -119,7 +105,7 @@ Foam::Istream& Foam::operator>>(Istream& is, phasePairKey& key)
|
||||
{
|
||||
key.ordered_ = false;
|
||||
}
|
||||
else if(temp[1] == "in")
|
||||
else if (temp[1] == "in")
|
||||
{
|
||||
key.ordered_ = true;
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ SourceFiles
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
// Forward declarations
|
||||
|
||||
class phasePairKey;
|
||||
|
||||
@ -59,48 +59,36 @@ class phasePairKey
|
||||
:
|
||||
public Pair<word>
|
||||
{
|
||||
public:
|
||||
|
||||
class hash
|
||||
:
|
||||
public Hash<phasePairKey>
|
||||
{
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
// Construct null
|
||||
hash();
|
||||
|
||||
|
||||
// Member operators
|
||||
|
||||
// Generate a hash from a phase pair key
|
||||
label operator()(const phasePairKey& key) const;
|
||||
};
|
||||
|
||||
|
||||
private:
|
||||
|
||||
// Private data
|
||||
|
||||
//- Flag to indicate whether ordering is important
|
||||
bool ordered_;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
struct hash
|
||||
{
|
||||
// Generate a hash from a phase pair key
|
||||
label operator()(const phasePairKey& key) const;
|
||||
};
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
phasePairKey();
|
||||
phasePairKey() {} // = default
|
||||
|
||||
//- Construct from names and the ordering flag
|
||||
phasePairKey(const word& name1, const word& name2, const bool ordered);
|
||||
phasePairKey
|
||||
(
|
||||
const word& name1,
|
||||
const word& name2,
|
||||
const bool ordered
|
||||
);
|
||||
|
||||
|
||||
// Destructor
|
||||
virtual ~phasePairKey();
|
||||
virtual ~phasePairKey() = default;
|
||||
|
||||
|
||||
// Friend Operators
|
||||
|
||||
Reference in New Issue
Block a user