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