* Made ASSERT definition conditional to avoid clashes.
* Automatic whitespace cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29408 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -49,9 +49,11 @@ All rights reserved.
|
|||||||
#include <new.h>
|
#include <new.h>
|
||||||
|
|
||||||
// don't include <Debug.h>
|
// don't include <Debug.h>
|
||||||
#define ASSERT(E) (void)0
|
#ifndef ASSERT
|
||||||
|
# define ASSERT(E) (void)0
|
||||||
|
#endif
|
||||||
#define TRESPASS() (void)0
|
#define TRESPASS() (void)0
|
||||||
|
|
||||||
//namespace BPrivate {
|
//namespace BPrivate {
|
||||||
|
|
||||||
template <class Element>
|
template <class Element>
|
||||||
@@ -89,17 +91,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 +118,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 +191,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 +209,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 +228,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 +266,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 +289,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 +301,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 +319,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 +421,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 +462,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 +488,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
|
||||||
|
|||||||
@@ -52,9 +52,11 @@ All rights reserved.
|
|||||||
#include "Misc.h"
|
#include "Misc.h"
|
||||||
|
|
||||||
// don't include <Debug.h>
|
// don't include <Debug.h>
|
||||||
#define ASSERT(E) (void)0
|
#ifndef ASSERT
|
||||||
|
# define ASSERT(E) (void)0
|
||||||
|
#endif
|
||||||
#define TRESPASS() (void)0
|
#define TRESPASS() (void)0
|
||||||
|
|
||||||
//namespace BPrivate {
|
//namespace BPrivate {
|
||||||
|
|
||||||
template <class Element>
|
template <class Element>
|
||||||
@@ -92,16 +94,16 @@ 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 *);
|
void Remove(Element *);
|
||||||
|
|
||||||
// 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
|
||||||
@@ -118,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;
|
||||||
@@ -190,7 +192,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++)
|
||||||
@@ -208,12 +210,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);
|
||||||
@@ -227,21 +229,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;
|
||||||
@@ -265,7 +267,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)
|
OpenHashTable<Element, ElementVec>::Remove(Element *element)
|
||||||
{
|
{
|
||||||
_RehashIfNeeded();
|
_RehashIfNeeded();
|
||||||
@@ -287,7 +289,7 @@ OpenHashTable<Element, ElementVec>::Remove(Element *element)
|
|||||||
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 +301,7 @@ OpenHashTable<Element, ElementVec>::Remove(Element *element)
|
|||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
@@ -405,18 +407,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;
|
||||||
@@ -446,7 +448,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;
|
||||||
/*
|
/*
|
||||||
@@ -472,11 +474,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
|
||||||
|
|||||||
+24
-22
@@ -52,9 +52,11 @@ All rights reserved.
|
|||||||
#include "Misc.h"
|
#include "Misc.h"
|
||||||
|
|
||||||
// don't include <Debug.h>
|
// don't include <Debug.h>
|
||||||
#define ASSERT(E) (void)0
|
#ifndef ASSERT
|
||||||
|
# define ASSERT(E) (void)0
|
||||||
|
#endif
|
||||||
#define TRESPASS() (void)0
|
#define TRESPASS() (void)0
|
||||||
|
|
||||||
//namespace BPrivate {
|
//namespace BPrivate {
|
||||||
|
|
||||||
template <class Element>
|
template <class Element>
|
||||||
@@ -92,16 +94,16 @@ 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 *);
|
void Remove(Element *);
|
||||||
|
|
||||||
// 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
|
||||||
@@ -118,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;
|
||||||
@@ -190,7 +192,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++)
|
||||||
@@ -208,12 +210,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);
|
||||||
@@ -227,21 +229,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;
|
||||||
@@ -265,7 +267,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)
|
OpenHashTable<Element, ElementVec>::Remove(Element *element)
|
||||||
{
|
{
|
||||||
_RehashIfNeeded();
|
_RehashIfNeeded();
|
||||||
@@ -287,7 +289,7 @@ OpenHashTable<Element, ElementVec>::Remove(Element *element)
|
|||||||
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 +301,7 @@ OpenHashTable<Element, ElementVec>::Remove(Element *element)
|
|||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
@@ -405,18 +407,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;
|
||||||
@@ -446,7 +448,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;
|
||||||
/*
|
/*
|
||||||
@@ -472,11 +474,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
|
||||||
|
|||||||
Reference in New Issue
Block a user