ramfs: Adapt NodeTable to use BOpenHashTable.
This commit is contained in:
@@ -38,6 +38,8 @@ public:
|
|||||||
|
|
||||||
virtual status_t InitCheck() const;
|
virtual status_t InitCheck() const;
|
||||||
|
|
||||||
|
Node*& HashLink() { return fHashLink; }
|
||||||
|
|
||||||
inline void SetVolume(Volume *volume) { fVolume = volume; }
|
inline void SetVolume(Volume *volume) { fVolume = volume; }
|
||||||
inline Volume *GetVolume() const { return fVolume; }
|
inline Volume *GetVolume() const { return fVolume; }
|
||||||
|
|
||||||
@@ -109,6 +111,7 @@ public:
|
|||||||
virtual void GetAllocationInfo(AllocationInfo &info);
|
virtual void GetAllocationInfo(AllocationInfo &info);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Node *fHashLink;
|
||||||
Volume *fVolume;
|
Volume *fVolume;
|
||||||
ino_t fID;
|
ino_t fID;
|
||||||
int32 fRefCount;
|
int32 fRefCount;
|
||||||
|
|||||||
@@ -8,9 +8,8 @@
|
|||||||
|
|
||||||
// constructor
|
// constructor
|
||||||
NodeTable::NodeTable()
|
NodeTable::NodeTable()
|
||||||
: fElementArray(1000),
|
|
||||||
fNodes(1000, &fElementArray)
|
|
||||||
{
|
{
|
||||||
|
fInitStatus = fNodes.Init(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// destructor
|
// destructor
|
||||||
@@ -22,8 +21,7 @@ NodeTable::~NodeTable()
|
|||||||
status_t
|
status_t
|
||||||
NodeTable::InitCheck() const
|
NodeTable::InitCheck() const
|
||||||
{
|
{
|
||||||
RETURN_ERROR(fNodes.InitCheck() && fElementArray.InitCheck()
|
RETURN_ERROR(fInitStatus);
|
||||||
? B_OK : B_NO_MEMORY);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddNode
|
// AddNode
|
||||||
@@ -32,12 +30,9 @@ NodeTable::AddNode(Node *node)
|
|||||||
{
|
{
|
||||||
status_t error = (node ? B_OK : B_BAD_VALUE);
|
status_t error = (node ? B_OK : B_BAD_VALUE);
|
||||||
if (error == B_OK) {
|
if (error == B_OK) {
|
||||||
NodeHashElement *element
|
if (fNodes.Lookup(node->GetID()) != nullptr)
|
||||||
= fNodes.Add(NodeHashElement::HashForID(node));
|
fNodes.Remove(node);
|
||||||
if (element)
|
SET_ERROR(error, fNodes.Insert(node));
|
||||||
element->fNode = node;
|
|
||||||
else
|
|
||||||
SET_ERROR(error, B_NO_MEMORY);
|
|
||||||
}
|
}
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
@@ -57,7 +52,7 @@ status_t
|
|||||||
NodeTable::RemoveNode(ino_t id)
|
NodeTable::RemoveNode(ino_t id)
|
||||||
{
|
{
|
||||||
status_t error = B_OK;
|
status_t error = B_OK;
|
||||||
if (NodeHashElement *element = _FindElement(id))
|
if (Node *element = fNodes.Lookup(id))
|
||||||
fNodes.Remove(element);
|
fNodes.Remove(element);
|
||||||
else
|
else
|
||||||
error = B_ERROR;
|
error = B_ERROR;
|
||||||
@@ -68,9 +63,7 @@ NodeTable::RemoveNode(ino_t id)
|
|||||||
Node *
|
Node *
|
||||||
NodeTable::GetNode(ino_t id)
|
NodeTable::GetNode(ino_t id)
|
||||||
{
|
{
|
||||||
Node *node = NULL;
|
Node *node = fNodes.Lookup(id);
|
||||||
if (NodeHashElement *element = _FindElement(id))
|
|
||||||
node = element->fNode;
|
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,23 +71,6 @@ NodeTable::GetNode(ino_t id)
|
|||||||
void
|
void
|
||||||
NodeTable::GetAllocationInfo(AllocationInfo &info)
|
NodeTable::GetAllocationInfo(AllocationInfo &info)
|
||||||
{
|
{
|
||||||
info.AddNodeTableAllocation(fNodes.ArraySize(), fNodes.VectorSize(),
|
info.AddNodeTableAllocation(0, fNodes.TableSize(),
|
||||||
sizeof(NodeHashElement),
|
sizeof(Node*), fNodes.CountElements());
|
||||||
fNodes.CountElements());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// _FindElement
|
|
||||||
NodeHashElement *
|
|
||||||
NodeTable::_FindElement(ino_t id) const
|
|
||||||
{
|
|
||||||
NodeHashElement *element
|
|
||||||
= fNodes.FindFirst(NodeHashElement::HashForID(id));
|
|
||||||
while (element && element->fNode->GetID() != id) {
|
|
||||||
if (element->fNext >= 0)
|
|
||||||
element = fNodes.ElementAt(element->fNext);
|
|
||||||
else
|
|
||||||
element = NULL;
|
|
||||||
}
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -5,44 +5,35 @@
|
|||||||
#ifndef NODE_TABLE_H
|
#ifndef NODE_TABLE_H
|
||||||
#define NODE_TABLE_H
|
#define NODE_TABLE_H
|
||||||
|
|
||||||
|
#include <util/OpenHashTable.h>
|
||||||
|
|
||||||
#include "AllocationInfo.h"
|
#include "AllocationInfo.h"
|
||||||
#include "Node.h"
|
#include "Node.h"
|
||||||
#include "OpenHashTable.h"
|
|
||||||
|
|
||||||
// NodeHashElement
|
// NodeHash
|
||||||
class NodeHashElement : public OpenHashElement {
|
struct NodeHash {
|
||||||
public:
|
typedef ino_t KeyType;
|
||||||
NodeHashElement() : OpenHashElement(), fNode(NULL)
|
typedef Node ValueType;
|
||||||
|
|
||||||
|
size_t HashKey(KeyType key) const
|
||||||
{
|
{
|
||||||
fNext = -1;
|
return uint32(key & 0xffffffff);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint32 HashForID(ino_t id)
|
size_t Hash(ValueType* value) const
|
||||||
{
|
{
|
||||||
return uint32(id & 0xffffffff);
|
return HashKey(value->GetID());
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline uint32 HashForID(Node *node)
|
bool Compare(KeyType key, ValueType* value) const
|
||||||
{
|
{
|
||||||
return HashForID(node->GetID());
|
return value->GetID() == key;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline uint32 Hash() const
|
ValueType*& GetLink(ValueType* value) const
|
||||||
{
|
{
|
||||||
return HashForID(fNode);
|
return value->HashLink();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline bool operator==(const OpenHashElement &element) const
|
|
||||||
{
|
|
||||||
return (static_cast<const NodeHashElement&>(element).fNode == fNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void Adopt(NodeHashElement &element)
|
|
||||||
{
|
|
||||||
fNode = element.fNode;
|
|
||||||
}
|
|
||||||
|
|
||||||
Node *fNode;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// NodeTable
|
// NodeTable
|
||||||
@@ -62,15 +53,8 @@ public:
|
|||||||
void GetAllocationInfo(AllocationInfo &info);
|
void GetAllocationInfo(AllocationInfo &info);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
NodeHashElement *_FindElement(ino_t id) const;
|
BOpenHashTable<NodeHash> fNodes;
|
||||||
|
status_t fInitStatus;
|
||||||
private:
|
|
||||||
OpenHashElementArray<NodeHashElement> fElementArray;
|
|
||||||
OpenHashTable<NodeHashElement, OpenHashElementArray<NodeHashElement> >
|
|
||||||
fNodes;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// undefine the PRINT from <Debug.h>
|
|
||||||
//#undef PRINT
|
|
||||||
|
|
||||||
#endif // NODE_TABLE_H
|
#endif // NODE_TABLE_H
|
||||||
|
|||||||
Reference in New Issue
Block a user