1 /* 2 * Copyright 2007, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * All rights reserved. Distributed under the terms of the MIT license. 4 */ 5 6 #include "DebugSupport.h" 7 #include "NodeTable.h" 8 9 // constructor 10 NodeTable::NodeTable() 11 { 12 fInitStatus = fNodes.Init(1000); 13 } 14 15 // destructor 16 NodeTable::~NodeTable() 17 { 18 } 19 20 // InitCheck 21 status_t 22 NodeTable::InitCheck() const 23 { 24 RETURN_ERROR(fInitStatus); 25 } 26 27 // AddNode 28 status_t 29 NodeTable::AddNode(Node *node) 30 { 31 status_t error = (node ? B_OK : B_BAD_VALUE); 32 if (error == B_OK) { 33 if (fNodes.Lookup(node->GetID()) != NULL) 34 fNodes.Remove(node); 35 SET_ERROR(error, fNodes.Insert(node)); 36 } 37 return error; 38 } 39 40 // RemoveNode 41 status_t 42 NodeTable::RemoveNode(Node *node) 43 { 44 status_t error = (node ? B_OK : B_BAD_VALUE); 45 if (error == B_OK) 46 error = RemoveNode(node->GetID()); 47 return error; 48 } 49 50 // RemoveNode 51 status_t 52 NodeTable::RemoveNode(ino_t id) 53 { 54 status_t error = B_OK; 55 if (Node *element = fNodes.Lookup(id)) 56 fNodes.Remove(element); 57 else 58 error = B_ERROR; 59 return error; 60 } 61 62 // GetNode 63 Node * 64 NodeTable::GetNode(ino_t id) 65 { 66 Node *node = fNodes.Lookup(id); 67 return node; 68 } 69 70 // GetAllocationInfo 71 void 72 NodeTable::GetAllocationInfo(AllocationInfo &info) 73 { 74 info.AddNodeTableAllocation(0, fNodes.TableSize(), 75 sizeof(Node*), fNodes.CountElements()); 76 } 77