OpenSDN source code
index_allocator.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2016 Juniper Networks, Inc. All rights reserved.
3
* Copyright Contributors to the OpenSDN project
4
*/
5
#include "
base/index_allocator.h
"
6
#include "
base/util.h
"
7
8
size_t
IndexAllocator::AllocIndex
() {
9
size_t
index =
BitSet::npos
;
10
if
(
last_index_
==
BitSet::npos
) {
11
index =
bitset_
.
find_first_clear
();
12
}
else
{
13
index =
bitset_
.
find_next_clear
(
last_index_
);
14
if
(index >
max_index_
) {
15
index =
bitset_
.
find_first_clear
();
16
}
17
}
18
19
if
(index >
max_index_
) index =
BitSet::npos
;
20
if
(index !=
BitSet::npos
) {
21
bitset_
.
set
(index);
22
}
23
last_index_
= index;
24
return
index;
25
}
26
27
void
IndexAllocator::FreeIndex
(
size_t
index) {
28
assert(index <=
max_index_
);
29
bitset_
.
reset
(index);
30
}
31
32
bool
IndexAllocator::NoneIndexSet
() {
33
return
bitset_
.
none
();
34
}
35
36
bool
IndexAllocator::AnyIndexSet
() {
37
return
bitset_
.
any
();
38
}
BitSet::find_first_clear
size_t find_first_clear() const
Definition:
bitset.cc:308
BitSet::none
bool none() const
Definition:
bitset.cc:173
BitSet::reset
BitSet & reset(size_t pos)
Definition:
bitset.cc:137
BitSet::npos
static const size_t npos
Definition:
bitset.h:20
BitSet::find_next_clear
size_t find_next_clear(size_t pos) const
Definition:
bitset.cc:325
BitSet::any
bool any() const
Definition:
bitset.cc:180
BitSet::set
BitSet & set(size_t pos)
Definition:
bitset.cc:126
IndexAllocator::AnyIndexSet
bool AnyIndexSet()
Definition:
index_allocator.cc:36
IndexAllocator::FreeIndex
void FreeIndex(size_t index)
Definition:
index_allocator.cc:27
IndexAllocator::AllocIndex
size_t AllocIndex()
Definition:
index_allocator.cc:8
IndexAllocator::max_index_
size_t max_index_
Definition:
index_allocator.h:27
IndexAllocator::last_index_
size_t last_index_
Definition:
index_allocator.h:28
IndexAllocator::NoneIndexSet
bool NoneIndexSet()
Definition:
index_allocator.cc:32
IndexAllocator::bitset_
BitSet bitset_
Definition:
index_allocator.h:26
index_allocator.h
util.h
contrail
src
contrail-common
base
index_allocator.cc
Generated by
1.9.1