1/* 2 * Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * All rights reserved. Distributed under the terms of the MIT license. 4 */ 5#ifndef NODE_TABLE_H 6#define NODE_TABLE_H 7 8#include <util/OpenHashTable.h> 9 10#include "AllocationInfo.h" 11#include "Node.h" 12 13// NodeHash 14struct NodeHash { 15 typedef ino_t KeyType; 16 typedef Node ValueType; 17 18 size_t HashKey(KeyType key) const 19 { 20 return uint32(key & 0xffffffff); 21 } 22 23 size_t Hash(ValueType* value) const 24 { 25 return HashKey(value->GetID()); 26 } 27 28 bool Compare(KeyType key, ValueType* value) const 29 { 30 return value->GetID() == key; 31 } 32 33 ValueType*& GetLink(ValueType* value) const 34 { 35 return value->HashLink(); 36 } 37}; 38 39// NodeTable 40class NodeTable { 41public: 42 NodeTable(); 43 ~NodeTable(); 44 45 status_t InitCheck() const; 46 47 status_t AddNode(Node *node); 48 status_t RemoveNode(Node *node); 49 status_t RemoveNode(ino_t id); 50 Node *GetNode(ino_t id); 51 52 // debugging 53 void GetAllocationInfo(AllocationInfo &info); 54 55private: 56 BOpenHashTable<NodeHash> fNodes; 57 status_t fInitStatus; 58}; 59 60#endif // NODE_TABLE_H 61