* Fixed build when Debug.h had already been included.

* Automatic whitespace cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29869 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-04-02 16:08:13 +00:00
parent 49fb53ee7e
commit b4c1445fae
+28 -24
View File
@@ -49,9 +49,13 @@ All rights reserved.
#include <new> #include <new>
// don't include <Debug.h> // don't include <Debug.h>
#define ASSERT(E) (void)0 #ifndef ASSERT
#define TRESPASS() (void)0 # define ASSERT(E) (void)0
#endif
#ifndef TRESPASS
# define TRESPASS() (void)0
#endif
namespace BPrivate { namespace BPrivate {
template <class Element> template <class Element>
@@ -89,17 +93,17 @@ public:
// it is up to the subclass of OpenHashTable to supply // it is up to the subclass of OpenHashTable to supply
// elementVector // elementVector
~OpenHashTable(); ~OpenHashTable();
bool InitCheck() const; bool InitCheck() const;
void SetElementVector(ElementVec *elementVector); void SetElementVector(ElementVec *elementVector);
Element *FindFirst(uint32 elementHash) const; Element *FindFirst(uint32 elementHash) const;
Element *Add(uint32 elementHash); Element *Add(uint32 elementHash);
void Remove(Element *element, bool dontRehash = false); void Remove(Element *element, bool dontRehash = false);
void RemoveAll(); void RemoveAll();
// when calling Add, any outstanding element pointer may become // when calling Add, any outstanding element pointer may become
// invalid; to deal with this, get the element index and restore // invalid; to deal with this, get the element index and restore
// it after the add // it after the add
@@ -116,7 +120,7 @@ protected:
private: private:
bool _RehashIfNeeded(); bool _RehashIfNeeded();
bool _Rehash(); bool _Rehash();
int32 fArraySize; int32 fArraySize;
int32 fInitialSize; int32 fInitialSize;
int32 fElementCount; int32 fElementCount;
@@ -189,7 +193,7 @@ OpenHashTable<Element, ElementVec>::InitCheck() const
} }
template<class Element, class ElementVec> template<class Element, class ElementVec>
int32 int32
OpenHashTable<Element, ElementVec>::OptimalSize(int32 minSize) OpenHashTable<Element, ElementVec>::OptimalSize(int32 minSize)
{ {
for (int32 index = 0; ; index++) for (int32 index = 0; ; index++)
@@ -207,12 +211,12 @@ OpenHashTable<Element, ElementVec>::FindFirst(uint32 hash) const
hash %= fArraySize; hash %= fArraySize;
if (fHashArray[hash] < 0) if (fHashArray[hash] < 0)
return 0; return 0;
return &fElementVector->At(fHashArray[hash]); return &fElementVector->At(fHashArray[hash]);
} }
template<class Element, class ElementVec> template<class Element, class ElementVec>
int32 int32
OpenHashTable<Element, ElementVec>::ElementIndex(const Element *element) const OpenHashTable<Element, ElementVec>::ElementIndex(const Element *element) const
{ {
return fElementVector->IndexOf(*element); return fElementVector->IndexOf(*element);
@@ -226,21 +230,21 @@ OpenHashTable<Element, ElementVec>::ElementAt(int32 index) const
} }
template<class Element, class ElementVec> template<class Element, class ElementVec>
int32 int32
OpenHashTable<Element, ElementVec>::ArraySize() const OpenHashTable<Element, ElementVec>::ArraySize() const
{ {
return fArraySize; return fArraySize;
} }
template<class Element, class ElementVec> template<class Element, class ElementVec>
int32 int32
OpenHashTable<Element, ElementVec>::VectorSize() const OpenHashTable<Element, ElementVec>::VectorSize() const
{ {
return fElementVector->Size(); return fElementVector->Size();
} }
template<class Element, class ElementVec> template<class Element, class ElementVec>
int32 int32
OpenHashTable<Element, ElementVec>::CountElements() const OpenHashTable<Element, ElementVec>::CountElements() const
{ {
return fElementCount; return fElementCount;
@@ -264,7 +268,7 @@ OpenHashTable<Element, ElementVec>::Add(uint32 hash)
} }
template<class Element, class ElementVec> template<class Element, class ElementVec>
void void
OpenHashTable<Element, ElementVec>::Remove(Element *element, bool dontRehash) OpenHashTable<Element, ElementVec>::Remove(Element *element, bool dontRehash)
{ {
if (!dontRehash) if (!dontRehash)
@@ -287,7 +291,7 @@ OpenHashTable<Element, ElementVec>::Remove(Element *element, bool dontRehash)
TRESPASS(); TRESPASS();
return; return;
} }
if (&fElementVector->At(next) == element) { if (&fElementVector->At(next) == element) {
fElementVector->At(index).fNext = element->fNext; fElementVector->At(index).fNext = element->fNext;
fElementVector->Remove(next); fElementVector->Remove(next);
@@ -299,7 +303,7 @@ OpenHashTable<Element, ElementVec>::Remove(Element *element, bool dontRehash)
} }
template<class Element, class ElementVec> template<class Element, class ElementVec>
void void
OpenHashTable<Element, ElementVec>::RemoveAll() OpenHashTable<Element, ElementVec>::RemoveAll()
{ {
for (int32 i = 0; fElementCount > 0 && i < fArraySize; i++) { for (int32 i = 0; fElementCount > 0 && i < fArraySize; i++) {
@@ -317,7 +321,7 @@ OpenHashTable<Element, ElementVec>::RemoveAll()
} }
template<class Element, class ElementVec> template<class Element, class ElementVec>
void void
OpenHashTable<Element, ElementVec>::SetElementVector(ElementVec *elementVector) OpenHashTable<Element, ElementVec>::SetElementVector(ElementVec *elementVector)
{ {
fElementVector = elementVector; fElementVector = elementVector;
@@ -419,18 +423,18 @@ OpenHashElementArray<Element>::At(int32 index) const
} }
template<class Element> template<class Element>
int32 int32
OpenHashElementArray<Element>::IndexOf(const Element &element) const OpenHashElementArray<Element>::IndexOf(const Element &element) const
{ {
int32 result = &element - fData; int32 result = &element - fData;
if (result < 0 || result > fSize) if (result < 0 || result > fSize)
return -1; return -1;
return result; return result;
} }
template<class Element> template<class Element>
int32 int32
OpenHashElementArray<Element>::Size() const OpenHashElementArray<Element>::Size() const
{ {
return fSize; return fSize;
@@ -460,7 +464,7 @@ OpenHashElementArray<Element>::Add()
int32 index = fNextFree; int32 index = fNextFree;
if (fNextDeleted >= 0) { if (fNextDeleted >= 0) {
index = fNextDeleted; index = fNextDeleted;
fNextDeleted = At(index).fNext; fNextDeleted = At(index).fNext;
} else if (fNextFree >= fSize - 1) { } else if (fNextFree >= fSize - 1) {
int32 newSize = fSize + kGrowChunk; int32 newSize = fSize + kGrowChunk;
/* /*
@@ -486,11 +490,11 @@ OpenHashElementArray<Element>::Add()
// call placement new to initialize the element properly // call placement new to initialize the element properly
ASSERT(At(index).fNext == -1); ASSERT(At(index).fNext == -1);
return &At(index); return &At(index);
} }
template<class Element> template<class Element>
void void
OpenHashElementArray<Element>::Remove(int32 index) OpenHashElementArray<Element>::Remove(int32 index)
{ {
// delete by chaining empty elements in a single linked // delete by chaining empty elements in a single linked