renamed 'empty' class to 'nil', added missing empty() member to some containers

This commit is contained in:
Mark Olesen
2009-01-09 13:10:10 +01:00
parent 036a1cd504
commit f0341171ff
24 changed files with 120 additions and 57 deletions

View File

@ -39,7 +39,7 @@ int main(int argc, char *argv[])
wordHashSet setA(0); wordHashSet setA(0);
HashTable<label, word> tableA; HashTable<label, word> tableA;
HashTable<empty> tableB; HashTable<nil> tableB;
Map<label> mapA; Map<label> mapA;
setA.insert("kjhk"); setA.insert("kjhk");
@ -49,9 +49,9 @@ int main(int argc, char *argv[])
tableA.insert("value2", 2); tableA.insert("value2", 2);
tableA.insert("value3", 3); tableA.insert("value3", 3);
tableB.insert("value4", empty()); tableB.insert("value4", nil());
tableB.insert("value5", empty()); tableB.insert("value5", nil());
tableB.insert("value6", empty()); tableB.insert("value6", nil());
mapA.set(1, 1); mapA.set(1, 1);
mapA.set(2, 2); mapA.set(2, 2);
@ -66,7 +66,7 @@ int main(int argc, char *argv[])
Info<< wordHashSet(setA) << endl; Info<< wordHashSet(setA) << endl;
Info<< "create from HashTable<T>: "; Info<< "create from HashTable<T>: ";
Info<< wordHashSet(tableA) << endl; Info<< wordHashSet(tableA) << endl;
Info<< "create from HashTable<empty>: "; Info<< "create from HashTable<nil>: ";
Info<< wordHashSet(tableB) << endl; Info<< wordHashSet(tableB) << endl;
Info<< "create from Map<label>: "; Info<< "create from Map<label>: ";

View File

@ -35,7 +35,7 @@ template<class Key, class Hash>
template<class T> template<class T>
Foam::HashSet<Key, Hash>::HashSet(const HashTable<T, Key, Hash>& ht) Foam::HashSet<Key, Hash>::HashSet(const HashTable<T, Key, Hash>& ht)
: :
HashTable<empty, Key, Hash>(ht.size()) HashTable<nil, Key, Hash>(ht.size())
{ {
for for
( (

View File

@ -46,7 +46,7 @@ Description
#define HashSet_H #define HashSet_H
#include "HashTable.H" #include "HashTable.H"
#include "empty.H" #include "nil.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -60,13 +60,13 @@ namespace Foam
template<class Key=word, class Hash=string::hash> template<class Key=word, class Hash=string::hash>
class HashSet class HashSet
: :
public HashTable<empty, Key, Hash> public HashTable<nil, Key, Hash>
{ {
public: public:
typedef typename HashTable<empty, Key, Hash>::iterator iterator; typedef typename HashTable<nil, Key, Hash>::iterator iterator;
typedef typename HashTable<empty, Key, Hash>::const_iterator const_iterator; typedef typename HashTable<nil, Key, Hash>::const_iterator const_iterator;
// Constructors // Constructors
@ -74,19 +74,19 @@ public:
//- Construct given initial size //- Construct given initial size
HashSet(label size = 100) HashSet(label size = 100)
: :
HashTable<empty, Key, Hash>(size) HashTable<nil, Key, Hash>(size)
{} {}
//- Construct from Istream //- Construct from Istream
HashSet(Istream& is) HashSet(Istream& is)
: :
HashTable<empty, Key, Hash>(is) HashTable<nil, Key, Hash>(is)
{} {}
//- Construct from UList of Key //- Construct from UList of Key
HashSet(const UList<Key>& lst) HashSet(const UList<Key>& lst)
: :
HashTable<empty, Key, Hash>(2*lst.size()) HashTable<nil, Key, Hash>(2*lst.size())
{ {
forAll(lst, i) forAll(lst, i)
{ {
@ -97,19 +97,19 @@ public:
//- Construct as copy //- Construct as copy
HashSet(const HashSet<Key, Hash>& hs) HashSet(const HashSet<Key, Hash>& hs)
: :
HashTable<empty, Key, Hash>(hs) HashTable<nil, Key, Hash>(hs)
{} {}
//- Construct by transferring the parameter contents //- Construct by transferring the parameter contents
HashSet(const Xfer<HashSet<Key, Hash> >& hs) HashSet(const Xfer<HashSet<Key, Hash> >& hs)
: :
HashTable<empty, Key, Hash>(hs) HashTable<nil, Key, Hash>(hs)
{} {}
//- Construct by transferring the parameter contents //- Construct by transferring the parameter contents
HashSet(const Xfer<HashTable<empty, Key, Hash> >& hs) HashSet(const Xfer<HashTable<nil, Key, Hash> >& hs)
: :
HashTable<empty, Key, Hash>(hs) HashTable<nil, Key, Hash>(hs)
{} {}
//- Construct from table of contents of the HashTable //- Construct from table of contents of the HashTable
@ -123,13 +123,13 @@ public:
//- Insert a new entry //- Insert a new entry
bool insert(const Key& key) bool insert(const Key& key)
{ {
return HashTable<empty, Key, Hash>::insert(key, empty()); return HashTable<nil, Key, Hash>::insert(key, nil());
} }
//- Same as insert (cannot overwrite empty content) //- Same as insert (cannot overwrite nil content)
bool set(const Key& key) bool set(const Key& key)
{ {
return HashTable<empty, Key, Hash>::insert(key, empty()); return HashTable<nil, Key, Hash>::insert(key, nil());
} }

View File

@ -171,6 +171,9 @@ public:
//- Return number of elements in table. //- Return number of elements in table.
inline label size() const; inline label size() const;
//- Return true if the hash table is empty
inline bool empty() const;
//- Return true if hashedEntry is found in table //- Return true if hashedEntry is found in table
bool found(const Key&) const; bool found(const Key&) const;

View File

@ -51,6 +51,13 @@ inline Foam::label Foam::HashTable<T, Key, Hash>::size() const
} }
template<class T, class Key, class Hash>
inline bool Foam::HashTable<T, Key, Hash>::empty() const
{
return (nElmts_ == 0);
}
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
inline bool Foam::HashTable<T, Key, Hash>::insert inline bool Foam::HashTable<T, Key, Hash>::insert
( (

View File

@ -164,6 +164,9 @@ public:
//- Return number of elements in table. //- Return number of elements in table.
inline label size() const; inline label size() const;
//- Return true if the hash table is empty
inline bool empty() const;
//- Return true if hashed entry is found in table //- Return true if hashed entry is found in table
bool found(const Key& key) const; bool found(const Key& key) const;

View File

@ -38,6 +38,13 @@ inline Foam::label Foam::StaticHashTable<T, Key, Hash>::size() const
} }
template<class T, class Key, class Hash>
inline bool Foam::StaticHashTable<T, Key, Hash>::empty() const
{
return (nElmts_ == 0);
}
template<class T, class Key, class Hash> template<class T, class Key, class Hash>
inline bool Foam::StaticHashTable<T, Key, Hash>::insert inline bool Foam::StaticHashTable<T, Key, Hash>::insert
( (

View File

@ -122,6 +122,9 @@ public:
//- Return number of elements in list //- Return number of elements in list
inline label size() const; inline label size() const;
//- Return true if the list is empty
inline bool empty() const;
//- Return first entry //- Return first entry
inline link* first(); inline link* first();

View File

@ -81,6 +81,12 @@ inline Foam::label Foam::DLListBase::size() const
} }
inline bool Foam::DLListBase::empty() const
{
return (nElmts_ == 0);
}
inline Foam::DLListBase::link* inline Foam::DLListBase::link*
Foam::DLListBase::first() Foam::DLListBase::first()
{ {

View File

@ -119,6 +119,9 @@ public:
//- Return number of elements in list //- Return number of elements in list
inline label size() const; inline label size() const;
//- Return true if the list is empty
inline bool empty() const;
//- Return first entry //- Return first entry
inline link* first(); inline link* first();

View File

@ -71,6 +71,12 @@ inline Foam::label Foam::SLListBase::size() const
} }
inline bool Foam::SLListBase::empty() const
{
return (nElmts_ == 0);
}
inline Foam::SLListBase::link* inline Foam::SLListBase::link*
Foam::SLListBase::first() Foam::SLListBase::first()
{ {

View File

@ -92,15 +92,6 @@ public:
} }
// Check
//- Is the stack empty
bool empty() const
{
return this->size() == 0;
}
// Edit // Edit
//- Push an element onto the stack //- Push an element onto the stack

View File

@ -92,15 +92,6 @@ public:
} }
// Check
//- Is the stack empty
bool empty() const
{
return this->size() == 0;
}
// Edit // Edit
//- Push an element onto the stack //- Push an element onto the stack

View File

@ -75,6 +75,8 @@ public:
// Access // Access
inline label size() const; inline label size() const;
inline bool empty() const;
inline const UList<T>& posList() const; inline const UList<T>& posList() const;
inline const UList<T>& negList() const; inline const UList<T>& negList() const;
inline const List<label>& addressing() const; inline const List<label>& addressing() const;

View File

@ -49,6 +49,13 @@ inline Foam::label Foam::BiIndirectList<T>::size() const
} }
template<class T>
inline bool Foam::BiIndirectList<T>::empty() const
{
return addressing_.empty();
}
template<class T> template<class T>
inline const Foam::UList<T>& Foam::BiIndirectList<T>::posList() const inline const Foam::UList<T>& Foam::BiIndirectList<T>::posList() const
{ {

View File

@ -126,6 +126,9 @@ public:
//- Return the primary size, i.e. the number of rows //- Return the primary size, i.e. the number of rows
inline label size() const; inline label size() const;
//- Return true if the number of rows is zero
inline bool empty() const;
//- Return the offset table //- Return the offset table
inline const List<label>& offsets() const; inline const List<label>& offsets() const;

View File

@ -74,6 +74,13 @@ inline Foam::label Foam::CompactListList<T>::size() const
} }
template<class T>
inline bool Foam::CompactListList<T>::empty() const
{
return offsets_.empty();
}
template<class T> template<class T>
inline const Foam::List<Foam::label>& Foam::CompactListList<T>::offsets() const inline const Foam::List<Foam::label>& Foam::CompactListList<T>::offsets() const
{ {

View File

@ -69,6 +69,8 @@ public:
// Access // Access
inline label size() const; inline label size() const;
inline bool empty() const;
inline const UList<T>& completeList() const; inline const UList<T>& completeList() const;
inline const List<label>& addressing() const; inline const List<label>& addressing() const;

View File

@ -47,6 +47,13 @@ inline Foam::label Foam::IndirectList<T>::size() const
} }
template<class T>
inline bool Foam::IndirectList<T>::empty() const
{
return addressing_.empty();
}
template<class T> template<class T>
inline const Foam::UList<T>& Foam::IndirectList<T>::completeList() const inline const Foam::UList<T>& Foam::IndirectList<T>::completeList() const
{ {

View File

@ -166,6 +166,9 @@ public:
//- Number of packed elements //- Number of packed elements
inline label size() const; inline label size() const;
//- Return true if the list is empty (i.e., if size() == 0).
inline bool empty() const;
//- Get value at index I //- Get value at index I
inline unsigned int get(const label i) const; inline unsigned int get(const label i) const;

View File

@ -117,6 +117,13 @@ inline Foam::label Foam::PackedList<nBits>::size() const
} }
template<int nBits>
inline bool Foam::PackedList<nBits>::empty() const
{
return (size_ == 0);
}
// Get value at i // Get value at i
template<int nBits> template<int nBits>
inline unsigned int Foam::PackedList<nBits>::get(const label i) const inline unsigned int Foam::PackedList<nBits>::get(const label i) const

View File

@ -158,6 +158,9 @@ public:
//- Return the number of elements in the PtrList //- Return the number of elements in the PtrList
inline label size() const; inline label size() const;
//- Return true if the PtrList is empty (i.e., if size() == 0).
inline bool empty() const;
// Edit // Edit

View File

@ -38,6 +38,13 @@ inline Foam::label Foam::PtrList<T>::size() const
} }
template<class T>
inline bool Foam::PtrList<T>::empty() const
{
return ptrs_.empty();
}
template<class T> template<class T>
inline bool Foam::PtrList<T>::set(const label i) const inline bool Foam::PtrList<T>::set(const label i) const
{ {

View File

@ -23,20 +23,15 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class Class
Foam::empty Foam::nil
Description Description
A class without storage. Used, for example, in HashSet. A class without any storage. Used, for example, in HashSet.
SourceFiles
emptyI.H
empty.C
emptyIO.C
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#ifndef empty_H #ifndef nil_H
#define empty_H #define nil_H
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -49,17 +44,17 @@ class Ostream;
// Forward declaration of friend functions and operators // Forward declaration of friend functions and operators
class empty; class nil;
Istream& operator>>(Istream& is, empty&); Istream& operator>>(Istream&, nil&);
Ostream& operator<<(Ostream& os, const empty&); Ostream& operator<<(Ostream&, const nil&);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
Class empty Declaration Class nil Declaration
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
class empty class nil
{ {
public: public:
@ -67,22 +62,22 @@ public:
// Constructors // Constructors
//- Construct null //- Construct null
empty() nil()
{} {}
//- Construct from Istream //- Construct from Istream
empty(Istream&) nil(Istream&)
{} {}
// IOstream Operator // IOstream Operators
friend Istream& operator>>(Istream& is, empty&) friend Istream& operator>>(Istream& is, nil&)
{ {
return is; return is;
} }
friend Ostream& operator<<(Ostream& os, const empty&) friend Ostream& operator<<(Ostream& os, const nil&)
{ {
return os; return os;
} }