Line data Source code
1 : /* 2 : * Copyright (c) 2016 Juniper Networks, Inc. All rights reserved. 3 : */ 4 : 5 : #ifndef ctrlplane_index_allocator_h 6 : #define ctrlplane_index_allocator_h 7 : 8 : #include <assert.h> 9 : #include <inttypes.h> 10 : #include <string> 11 : #include <vector> 12 : #include <base/bitset.h> 13 : 14 : class IndexAllocator { 15 : public: 16 17 : IndexAllocator(size_t max_index) 17 17 : : max_index_(max_index), last_index_(BitSet::npos) { } 18 : 19 : size_t AllocIndex(); 20 : void FreeIndex(size_t index); 21 : bool NoneIndexSet(); 22 : bool AnyIndexSet(); 23 : 24 : private: 25 : BitSet bitset_; 26 : size_t max_index_; 27 : size_t last_index_; 28 : }; 29 : 30 : #endif