Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : */ 5 : 6 : #ifndef ctrlplane_ksync_index_table_h 7 : #define ctrlplane_ksync_index_table_h 8 : 9 : #include <boost/dynamic_bitset.hpp> 10 : 11 : class KSyncIndexTable { 12 : public: 13 664 : KSyncIndexTable() { }; 14 : 15 10 : KSyncIndexTable(unsigned int count) : table_(count) { 16 10 : table_.set(); 17 10 : }; 18 : 19 674 : ~KSyncIndexTable() { 20 : //assert(table_.count() == table_.size()); 21 674 : table_.clear(); 22 674 : }; 23 : 24 414 : size_t Alloc() { 25 414 : size_t index = table_.find_first(); 26 414 : assert(index != table_.npos); 27 414 : table_.set(index, 0); 28 414 : return index; 29 : }; 30 : 31 413 : void Free(size_t index) { 32 413 : assert(index < table_.size()); 33 413 : assert(table_[index] == 0); 34 413 : table_.set(index); 35 413 : }; 36 : 37 : private: 38 : typedef boost::dynamic_bitset<> Bitmap; 39 : Bitmap table_; 40 : }; 41 : 42 : #endif // ctrlplane_ksync_index_table_h