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