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