Commit 576d9388 authored by Mark Olesen's avatar Mark Olesen
Browse files

Preliminary work on hashing

- Hash returns unsigned
- FixedList templated on unsigned int
- include uLabel.H in UList, HashTable etc. so the output function is know
  throughout
parent a46c85f5
...@@ -39,9 +39,10 @@ SourceFiles ...@@ -39,9 +39,10 @@ SourceFiles
#define HashTable_H #define HashTable_H
#include "label.H" #include "label.H"
#include "uLabel.H"
#include "word.H" #include "word.H"
#include "className.H"
#include "Xfer.H" #include "Xfer.H"
#include "className.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
...@@ -45,9 +45,10 @@ SourceFiles ...@@ -45,9 +45,10 @@ SourceFiles
#define StaticHashTable_H #define StaticHashTable_H
#include "label.H" #include "label.H"
#include "uLabel.H"
#include "word.H" #include "word.H"
#include "className.H"
#include "Xfer.H" #include "Xfer.H"
#include "className.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
...@@ -38,6 +38,7 @@ SourceFiles ...@@ -38,6 +38,7 @@ SourceFiles
#define LList_H #define LList_H
#include "label.H" #include "label.H"
#include "uLabel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
...@@ -38,6 +38,7 @@ SourceFiles ...@@ -38,6 +38,7 @@ SourceFiles
#define UILList_H #define UILList_H
#include "label.H" #include "label.H"
#include "uLabel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
...@@ -38,6 +38,7 @@ SourceFiles ...@@ -38,6 +38,7 @@ SourceFiles
#include "bool.H" #include "bool.H"
#include "label.H" #include "label.H"
#include "uLabel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
...@@ -38,6 +38,7 @@ SourceFiles ...@@ -38,6 +38,7 @@ SourceFiles
#include "bool.H" #include "bool.H"
#include "label.H" #include "label.H"
#include "uLabel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
......
...@@ -31,7 +31,7 @@ License ...@@ -31,7 +31,7 @@ License
// * * * * * * * * * * * * * * STL Member Functions * * * * * * * * * * * * // // * * * * * * * * * * * * * * STL Member Functions * * * * * * * * * * * * //
template<class T, Foam::label Size> template<class T, unsigned Size>
void Foam::FixedList<T, Size>::swap(FixedList<T, Size>& a) void Foam::FixedList<T, Size>::swap(FixedList<T, Size>& a)
{ {
List_ACCESS(T, (*this), vp); List_ACCESS(T, (*this), vp);
...@@ -47,7 +47,7 @@ void Foam::FixedList<T, Size>::swap(FixedList<T, Size>& a) ...@@ -47,7 +47,7 @@ void Foam::FixedList<T, Size>::swap(FixedList<T, Size>& a)
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T, Foam::label Size> template<class T, unsigned Size>
bool Foam::FixedList<T, Size>::operator==(const FixedList<T, Size>& a) const bool Foam::FixedList<T, Size>::operator==(const FixedList<T, Size>& a) const
{ {
bool equal = true; bool equal = true;
...@@ -63,20 +63,20 @@ bool Foam::FixedList<T, Size>::operator==(const FixedList<T, Size>& a) const ...@@ -63,20 +63,20 @@ bool Foam::FixedList<T, Size>::operator==(const FixedList<T, Size>& a) const
} }
template<class T, Foam::label Size> template<class T, unsigned Size>
bool Foam::FixedList<T, Size>::operator!=(const FixedList<T, Size>& a) const bool Foam::FixedList<T, Size>::operator!=(const FixedList<T, Size>& a) const
{ {
return !operator==(a); return !operator==(a);
} }
template<class T, Foam::label Size> template<class T, unsigned Size>
bool Foam::FixedList<T, Size>::operator<(const FixedList<T, Size>& a) const bool Foam::FixedList<T, Size>::operator<(const FixedList<T, Size>& a) const
{ {
for for
( (
const_iterator vi = begin(), ai = a.begin(); const_iterator vi = cbegin(), ai = a.cbegin();
vi < end() && ai < a.end(); vi < cend() && ai < a.cend();
vi++, ai++ vi++, ai++
) )
{ {
...@@ -101,21 +101,21 @@ bool Foam::FixedList<T, Size>::operator<(const FixedList<T, Size>& a) const ...@@ -101,21 +101,21 @@ bool Foam::FixedList<T, Size>::operator<(const FixedList<T, Size>& a) const
} }
template<class T, Foam::label Size> template<class T, unsigned Size>
bool Foam::FixedList<T, Size>::operator>(const FixedList<T, Size>& a) const bool Foam::FixedList<T, Size>::operator>(const FixedList<T, Size>& a) const
{ {
return a.operator<(*this); return a.operator<(*this);
} }
template<class T, Foam::label Size> template<class T, unsigned Size>
bool Foam::FixedList<T, Size>::operator<=(const FixedList<T, Size>& a) const bool Foam::FixedList<T, Size>::operator<=(const FixedList<T, Size>& a) const
{ {
return !operator>(a); return !operator>(a);
} }
template<class T, Foam::label Size> template<class T, unsigned Size>
bool Foam::FixedList<T, Size>::operator>=(const FixedList<T, Size>& a) const bool Foam::FixedList<T, Size>::operator>=(const FixedList<T, Size>& a) const
{ {
return !operator<(a); return !operator<(a);
......
...@@ -38,7 +38,9 @@ SourceFiles ...@@ -38,7 +38,9 @@ SourceFiles
#ifndef FixedList_H #ifndef FixedList_H
#define FixedList_H #define FixedList_H
#include "bool.H"
#include "label.H" #include "label.H"
#include "uLabel.H"
#include "Hash.H" #include "Hash.H"
#include "autoPtr.H" #include "autoPtr.H"
...@@ -49,12 +51,12 @@ namespace Foam ...@@ -49,12 +51,12 @@ namespace Foam
// Forward declaration of friend functions and operators // Forward declaration of friend functions and operators
template<class T, label Size> class FixedList; template<class T, unsigned Size> class FixedList;
template<class T, label Size> template<class T, unsigned Size>
Istream& operator>>(Istream&, FixedList<T, Size>&); Istream& operator>>(Istream&, FixedList<T, Size>&);
template<class T, label Size> template<class T, unsigned Size>
Ostream& operator<<(Ostream&, const FixedList<T, Size>&); Ostream& operator<<(Ostream&, const FixedList<T, Size>&);
template<class T> class UList; template<class T> class UList;
...@@ -65,7 +67,7 @@ template<class T> class SLList; ...@@ -65,7 +67,7 @@ template<class T> class SLList;
Class FixedList Declaration Class FixedList Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
template<class T, label Size> template<class T, unsigned Size>
class FixedList class FixedList
{ {
// Private data // Private data
...@@ -78,14 +80,14 @@ public: ...@@ -78,14 +80,14 @@ public:
//- Hashing function class //- Hashing function class
// Rotating hash from http://burtleburtle.net/bob/hash/doobs.html // Rotating hash from http://burtleburtle.net/bob/hash/doobs.html
template<class HashT=Hash<T> > template< class HashT=Hash<T> >
class Hash class Hash
{ {
public: public:
Hash() Hash()
{} {}
label operator()(const FixedList<T, Size>&) const; inline unsigned operator()(const FixedList<T, Size>&) const;
}; };
// Static Member Functions // Static Member Functions
......
...@@ -29,44 +29,44 @@ License ...@@ -29,44 +29,44 @@ License
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T, Foam::label Size> template<class T, unsigned Size>
inline Foam::FixedList<T, Size>::FixedList() inline Foam::FixedList<T, Size>::FixedList()
{} {}
template<class T, Foam::label Size> template<class T, unsigned Size>
inline Foam::FixedList<T, Size>::FixedList(const T v[Size]) inline Foam::FixedList<T, Size>::FixedList(const T v[Size])
{ {
for (register label i=0; i<Size; i++) for (register unsigned i=0; i<Size; i++)
{ {
v_[i] = v[i]; v_[i] = v[i];
} }
} }
template<class T, Foam::label Size> template<class T, unsigned Size>
inline Foam::FixedList<T, Size>::FixedList(const T& t) inline Foam::FixedList<T, Size>::FixedList(const T& t)
{ {
for (register label i=0; i<Size; i++) for (register unsigned i=0; i<Size; i++)
{ {
v_[i] = t; v_[i] = t;
} }
} }
template<class T, Foam::label Size> template<class T, unsigned Size>
inline Foam::FixedList<T, Size>::FixedList(const UList<T>& lst) inline Foam::FixedList<T, Size>::FixedList(const UList<T>& lst)
{ {
checkSize(lst.size()); checkSize(lst.size());
for (register label i=0; i<Size; i++) for (register unsigned i=0; i<Size; i++)
{ {
v_[i] = lst[i]; v_[i] = lst[i];
} }
} }
template<class T, Foam::label Size> template<class T, unsigned Size>
inline Foam::FixedList<T, Size>::FixedList(const SLList<T>& lst) inline Foam::FixedList<T, Size>::FixedList(const SLList<T>& lst)
{ {
checkSize(lst.size()); checkSize(lst.size());
...@@ -84,41 +84,41 @@ inline Foam::FixedList<T, Size>::FixedList(const SLList<T>& lst) ...@@ -84,41 +84,41 @@ inline Foam::FixedList<T, Size>::FixedList(const SLList<T>& lst)
} }
template<class T, Foam::label Size> template<class T, unsigned Size>
inline Foam::FixedList<T, Size>::FixedList(const FixedList<T, Size>& lst) inline Foam::FixedList<T, Size>::FixedList(const FixedList<T, Size>& lst)
{ {
for (register label i=0; i<Size; i++) for (register unsigned i=0; i<Size; i++)
{ {
v_[i] = lst[i]; v_[i] = lst[i];
} }
} }
template<class T, Foam::label Size> template<class T, unsigned Size>
inline Foam::autoPtr<Foam::FixedList<T, Size> > inline Foam::autoPtr< Foam::FixedList<T, Size> >
Foam::FixedList<T, Size>::clone() const Foam::FixedList<T, Size>::clone() const
{ {
return autoPtr<FixedList<T, Size> >(new FixedList<T, Size>(*this)); return autoPtr< FixedList<T, Size> >(new FixedList<T, Size>(*this));
} }
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T, Foam::label Size> template<class T, unsigned Size>
inline const Foam::FixedList<T, Size>& Foam::FixedList<T, Size>::null() inline const Foam::FixedList<T, Size>& Foam::FixedList<T, Size>::null()
{ {
return *reinterpret_cast< FixedList<T, Size>* >(0); return *reinterpret_cast< FixedList<T, Size>* >(0);
} }
template<class T, Foam::label Size> template<class T, unsigned Size>
inline Foam::label Foam::FixedList<T, Size>::fcIndex(const label i) const inline Foam::label Foam::FixedList<T, Size>::fcIndex(const label i) const
{ {
return (i == Size-1 ? 0 : i+1); return (i == Size-1 ? 0 : i+1);
} }
template<class T, Foam::label Size> template<class T, unsigned Size>
inline Foam::label Foam::FixedList<T, Size>::rcIndex(const label i) const inline Foam::label Foam::FixedList<T, Size>::rcIndex(const label i) const
{ {
return (i ? i-1 : Size-1); return (i ? i-1 : Size-1);
...@@ -126,51 +126,51 @@ inline Foam::label Foam::FixedList<T, Size>::rcIndex(const label i) const ...@@ -126,51 +126,51 @@ inline Foam::label Foam::FixedList<T, Size>::rcIndex(const label i) const
// Check start is within valid range (0 ... size-1). // Check start is within valid range (0 ... size-1).
template<class T, Foam::label Size> template<class T, unsigned Size>
inline void Foam::FixedList<T, Size>::checkStart(const label start) const inline void Foam::FixedList<T, Size>::checkStart(const label start) const
{ {
if (start<0 || (start && start>=Size)) if (start < 0 || (start && unsigned(start) >= Size))
{ {
FatalErrorIn("FixedList<T, Size>::checkStart(const label)") FatalErrorIn("FixedList<T, Size>::checkStart(const label)")
<< "start " << start << " out of range 0 ... " << max(Size-1, 0) << "start " << start << " out of range 0 ... " << (Size-1)
<< abort(FatalError); << abort(FatalError);
} }
} }
// Check size is within valid range (0 ... size). // Check size is within valid range (0 ... size).
template<class T, Foam::label Size> template<class T, unsigned Size>
inline void Foam::FixedList<T, Size>::checkSize(const label size) const inline void Foam::FixedList<T, Size>::checkSize(const label size) const
{ {
if (size<0 || size>Size) if (size < 0 || unsigned(size) > Size)
{ {
FatalErrorIn("FixedList<T, Size>::checkSize(const label)") FatalErrorIn("FixedList<T, Size>::checkSize(const label)")
<< "size " << size << " out of range 0 ... " << Size << "size " << size << " out of range 0 ... " << (Size)
<< abort(FatalError); << abort(FatalError);
} }
} }
// Check index i is within valid range (0 ... size-1). // Check index i is within valid range (0 ... size-1).
template<class T, Foam::label Size> template<class T, unsigned Size>
inline void Foam::FixedList<T, Size>::checkIndex(const label i) const inline void Foam::FixedList<T, Size>::checkIndex(const label i) const
{ {
if (!Size) if (!Size)
{ {
FatalErrorIn("FixedList<T, Size>::checkIndex(const label)") FatalErrorIn("FixedList<T, Size>::checkIndex(const label)")
<< "attempt to access element from zero sized list" << "attempt to access element from zero-sized list"
<< abort(FatalError); << abort(FatalError);
} }
else if (i<0 || i>=Size) else if (i < 0 || i >= Size)
{ {
FatalErrorIn("FixedList<T, Size>::checkIndex(const label)") FatalErrorIn("FixedList<T, Size>::checkIndex(const label)")
<< "index " << i << " out of range 0 ... " << Size-1 << "index " << i << " out of range 0 ... " << (Size-1)
<< abort(FatalError); << abort(FatalError);
} }
} }
template<class T, Foam::label Size> template<class T, unsigned Size>
inline void Foam::FixedList<T, Size>::resize(const label s) inline void Foam::FixedList<T, Size>::resize(const label s)
{ {
# ifdef FULLDEBUG # ifdef FULLDEBUG
...@@ -178,7 +178,7 @@ inline void Foam::FixedList<T, Size>::resize(const label s) ...@@ -178,7 +178,7 @@ inline void Foam::FixedList<T, Size>::resize(const label s)
# endif # endif
} }
template<class T, Foam::label Size> template<class T, unsigned Size>
inline void Foam::FixedList<T, Size>::setSize(const label s) inline void Foam::FixedList<T, Size>::setSize(const label s)
{ {
# ifdef FULLDEBUG # ifdef FULLDEBUG
...@@ -186,17 +186,17 @@ inline void Foam::FixedList<T, Size>::setSize(const label s) ...@@ -186,17 +186,17 @@ inline void Foam::FixedList<T, Size>::setSize(const label s)
# endif # endif
} }
template<class T, Foam::label Size> template<class T, unsigned Size>
inline void Foam::FixedList<T, Size>::transfer(const FixedList<T, Size>& lst) inline void Foam::FixedList<T, Size>::transfer(const FixedList<T, Size>& lst)
{ {
for (register label i=0; i<Size; i++) for (register unsigned i=0; i<Size; i++)
{ {
v_[i] = lst[i]; v_[i] = lst[i];
} }
} }
template<class T, Foam::label Size> template<class T, unsigned Size>
inline const T* inline const T*
Foam::FixedList<T, Size>::cdata() const Foam::FixedList<T, Size>::cdata() const
{ {
...@@ -204,7 +204,7 @@ Foam::FixedList<T, Size>::cdata() const ...@@ -204,7 +204,7 @@ Foam::FixedList<T, Size>::cdata() const
} }
template<class T, Foam::label Size> template<class T, unsigned Size>
inline T* inline T*
Foam::FixedList<T, Size>::data() Foam::FixedList<T, Size>::data()
{ {
...@@ -215,7 +215,7 @@ Foam::FixedList<T, Size>::data() ...@@ -215,7 +215,7 @@ Foam::FixedList<T, Size>::data()
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
// element access // element access
template<class T, Foam::label Size> template<class T, unsigned Size>
inline T& Foam::FixedList<T, Size>::operator[](const label i) inline T& Foam::FixedList<T, Size>::operator[](const label i)
{ {
# ifdef FULLDEBUG