OpenSDN source code
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
index_allocator.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
3
*/
4
#include "
base/index_allocator.h
"
5
#include "
base/util.h
"
6
7
size_t
IndexAllocator::AllocIndex
() {
8
size_t
index =
BitSet::npos
;
9
if
(
last_index_
==
BitSet::npos
) {
10
index =
bitset_
.
find_first_clear
();
11
}
else
{
12
index =
bitset_
.
find_next_clear
(
last_index_
);
13
if
(index >
max_index_
) {
14
index =
bitset_
.
find_first_clear
();
15
}
16
}
17
18
if
(index >
max_index_
) index =
BitSet::npos
;
19
if
(index !=
BitSet::npos
) {
20
bitset_
.
set
(index);
21
}
22
last_index_
= index;
23
return
index;
24
}
25
26
void
IndexAllocator::FreeIndex
(
size_t
index) {
27
assert(index <=
max_index_
);
28
bitset_
.
reset
(index);
29
}
30
31
bool
IndexAllocator::NoneIndexSet
() {
32
return
bitset_
.
none
();
33
}
34
35
bool
IndexAllocator::AnyIndexSet
() {
36
return
bitset_
.
any
();
37
}
index_allocator.h
IndexAllocator::last_index_
size_t last_index_
Definition:
index_allocator.h:27
BitSet::reset
BitSet & reset(size_t pos)
Definition:
bitset.cc:136
IndexAllocator::NoneIndexSet
bool NoneIndexSet()
Definition:
index_allocator.cc:31
IndexAllocator::AnyIndexSet
bool AnyIndexSet()
Definition:
index_allocator.cc:35
IndexAllocator::max_index_
size_t max_index_
Definition:
index_allocator.h:26
BitSet::find_first_clear
size_t find_first_clear() const
Definition:
bitset.cc:307
IndexAllocator::AllocIndex
size_t AllocIndex()
Definition:
index_allocator.cc:7
BitSet::npos
static const size_t npos
Definition:
bitset.h:19
util.h
IndexAllocator::FreeIndex
void FreeIndex(size_t index)
Definition:
index_allocator.cc:26
BitSet::find_next_clear
size_t find_next_clear(size_t pos) const
Definition:
bitset.cc:324
IndexAllocator::bitset_
BitSet bitset_
Definition:
index_allocator.h:25
BitSet::set
BitSet & set(size_t pos)
Definition:
bitset.cc:125
BitSet::any
bool any() const
Definition:
bitset.cc:179
BitSet::none
bool none() const
Definition:
bitset.cc:172
contrail
src
contrail-common
base
index_allocator.cc
Generated by
1.8.5