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 30 : KSyncIndexTable() { }; 13 : 14 8 : KSyncIndexTable(unsigned int count) : table_(count) { 15 8 : table_.set(); 16 8 : }; 17 : 18 38 : ~KSyncIndexTable() { 19 : //assert(table_.count() == table_.size()); 20 38 : table_.clear(); 21 38 : }; 22 : 23 414 : size_t Alloc() { 24 414 : size_t index = table_.find_first(); 25 414 : assert(index != table_.npos); 26 414 : table_.set(index, 0); 27 414 : return index; 28 : }; 29 : 30 413 : void Free(size_t index) { 31 413 : assert(index < table_.size()); 32 413 : assert(table_[index] == 0); 33 413 : table_.set(index); 34 413 : }; 35 : 36 : private: 37 : typedef boost::dynamic_bitset<> Bitmap; 38 : Bitmap table_; 39 : }; 40 : 41 : #endif // ctrlplane_ksync_index_table_h