1// NodeTable.h 2 3#ifndef NODE_TABLE_H 4#define NODE_TABLE_H 5 6#include "AllocationInfo.h" 7#include "Node.h" 8#include "OpenHashTable.h" 9 10// NodeHashElement 11class NodeHashElement : public OpenHashElement { 12public: 13 NodeHashElement() : OpenHashElement(), fNode(NULL) 14 { 15 fNext = -1; 16 } 17 18 static inline uint32 HashForID(ino_t id) 19 { 20 return uint32(id & 0xffffffff); 21 } 22 23 static inline uint32 HashForID(Node *node) 24 { 25 return HashForID(node->GetID()); 26 } 27 28 inline uint32 Hash() const 29 { 30 return HashForID(fNode); 31 } 32 33 inline bool operator==(const OpenHashElement &element) const 34 { 35 return (static_cast<const NodeHashElement&>(element).fNode == fNode); 36 } 37 38 inline void Adopt(NodeHashElement &element) 39 { 40 fNode = element.fNode; 41 } 42 43 Node *fNode; 44}; 45 46// NodeTable 47class NodeTable { 48public: 49 NodeTable(); 50 ~NodeTable(); 51 52 status_t InitCheck() const; 53 54 status_t AddNode(Node *node); 55 status_t RemoveNode(Node *node); 56 status_t RemoveNode(ino_t id); 57 Node *GetNode(ino_t id); 58 59 // debugging 60 void GetAllocationInfo(AllocationInfo &info); 61 62private: 63 NodeHashElement *_FindElement(ino_t id) const; 64 65private: 66 OpenHashElementArray<NodeHashElement> fElementArray; 67 OpenHashTable<NodeHashElement, OpenHashElementArray<NodeHashElement> > 68 fNodes; 69}; 70 71// undefine the PRINT from <Debug.h> 72//#undef PRINT 73 74#endif // NODE_TABLE_H 75