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