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
bitvector_private.h
Go to the documentation of this file.
1
/* $Id: bitvector_private.h 346474 2009-11-14 10:18:58Z ssiano $
2
*
3
* bitvector_private.h - Bit vector manipulation private definitions
4
*
5
* Dave Katz, March 2008
6
*
7
* Copyright (c) 2008, Juniper Networks, Inc.
8
* All rights reserved.
9
*/
10
11
#ifndef __BITVECTOR_PRIVATE_H__
12
#define __BITVECTOR_PRIVATE_H__
13
14
/*
15
* This module defines a bit vector and a set of operations thereon.
16
*
17
* A bit vector is constructed out of a patricia tree of bit vector entries,
18
* each of which contains a block of bits and some housekeeping information.
19
*
20
* The patricia tree allows for rapid access to a bit vector entries, and
21
* also allows for sparse vectors (missing entries are equivalent to a set
22
* of all zero bits.)
23
*
24
* The size of a bit vector entry is defined in the environment file at
25
* compile time. Larger entries are more memory-efficient for larger
26
* vectors (less overhead), but less so for smaller vectors (more wasted
27
* space.) The computational cost is slightly higher for smaller entries
28
* when vectors are large.
29
*/
30
31
32
/*
33
* Size definitions
34
*
35
* Sizing is driven by the definition of BV_BITSIZE_LOG2, the base 2
36
* log of the number of bits in a vector entry. The size of each word
37
* in the vector is defined by bv_word_t. All are defined in the
38
* environment file.
39
*/
40
#define BV_BITSPERWORD (sizeof(bv_word_t) * 8)
/* Bits per word */
41
#define BV_BITSIZE (1 << (BV_BITSIZE_LOG2))
/* Number of bits per entry */
42
#define BV_WORDSIZE ((BV_BITSIZE + BV_BITSPERWORD - 1) / BV_BITSPERWORD)
43
44
45
/*
46
* Bit vector entry
47
*
48
* A bit vector entry contains a block of bits with a position offset.
49
* The bits are numbered from the low order position upward.
50
*
51
* Each block has a starting bit number (its offset into the overall
52
* bit vector) and is stored in a patricia tree with the starting bit
53
* number as the key.
54
*
55
* Entries that aren't completely full are threaded from the bit
56
* vector head to make finding a free bit easier.
57
*
58
* In general we try to keep a count of how many bits are set in this
59
* entry, since it speeds up some operations. However, in order to do
60
* fast vector operations we can't afford to keep track of the bit count,
61
* so once we lose track of the bit count we set it to BV_UNKNOWN_COUNT
62
* to flag this case.
63
*/
64
typedef
struct
bv_entry_
{
65
task_thread
bv_ent_nonfull_thread
;
/* Entry on non-full-entry thread */
66
bvx_patnode
bv_ent_node
;
/* Patricia node */
67
uint8_t
bv_key
[
sizeof
(
bv_bitnum_t
)];
/* Patricia key */
68
bv_bitnum_t
bv_start
;
/* Starting bit number */
69
int
bv_setcount
;
/* Number of set bits */
70
bv_word_t
bv_bits
[
BV_WORDSIZE
];
/* Actual bits */
71
}
bv_entry
;
72
73
BVX_PATNODE_TO_STRUCT
(bv_patnode_to_bv_entry,
bv_entry
, bv_ent_node);
74
THREAD_TO_STRUCT
(bv_thread_to_bv_entry,
bv_entry
, bv_ent_nonfull_thread);
75
76
#define BV_UNKNOWN_COUNT -1
/* bv_setcount unknown */
77
#define BV_ALLSET ((bv_word_t)(~0))
/* All-ones constant */
78
#define BV_MAX_BITNUM ((0x7fffffff - BV_BITSIZE) + 1)
/* Max bit num + 1 */
79
80
81
/*
82
* bv_start_bit
83
*
84
* Returns the starting bit number of the bit vector entry corresponding
85
* to a particular bit number.
86
*/
87
static
inline
bv_bitnum_t
88
bv_start_bit
(
bv_bitnum_t
bit_number)
89
{
90
return
bit_number & (~(
BV_BITSIZE
- 1));
91
}
92
93
94
/*
95
* bv_word_offset
96
*
97
* Returns the word offset into a vector entry of a bit vector word,
98
* given the bit number.
99
*
100
* Don't worry, all that integer math should be optimized to a shift and
101
* a mask.
102
*/
103
static
inline
uint32_t
104
bv_word_offset
(
bv_bitnum_t
bit_number)
105
{
106
return
((bit_number % (
BV_BITSIZE
)) /
BV_BITSPERWORD
);
107
}
108
109
/*
110
* bv_word_mask
111
*
112
* Returns the word mask corresponding to a bit, given the bit number.
113
*/
114
static
inline
bv_word_t
115
bv_word_mask
(
bv_bitnum_t
bit_number)
116
{
117
return
1 << (bit_number & (
BV_BITSPERWORD
- 1));
118
}
119
120
#endif
/* __BITVECTOR_PRIVATE_H__ */
bv_entry_::bv_ent_node
bvx_patnode bv_ent_node
Definition:
bitvector_private.h:66
thread_
Definition:
task_thread_api.h:10
bv_entry_::bv_ent_nonfull_thread
task_thread bv_ent_nonfull_thread
Definition:
bitvector_private.h:65
THREAD_TO_STRUCT
#define THREAD_TO_STRUCT(function, structure, member)
Definition:
task_thread_api.h:15
bv_entry_::bv_key
uint8_t bv_key[sizeof(bv_bitnum_t)]
Definition:
bitvector_private.h:67
bv_entry_::bv_bits
bv_word_t bv_bits[BV_WORDSIZE]
Definition:
bitvector_private.h:70
bv_entry_::bv_setcount
int bv_setcount
Definition:
bitvector_private.h:69
BV_BITSPERWORD
#define BV_BITSPERWORD
Definition:
bitvector_private.h:40
bv_entry
struct bv_entry_ bv_entry
bv_entry_
Definition:
bitvector_private.h:64
bv_word_mask
static bv_word_t bv_word_mask(bv_bitnum_t bit_number)
Definition:
bitvector_private.h:115
bv_start_bit
static bv_bitnum_t bv_start_bit(bv_bitnum_t bit_number)
Definition:
bitvector_private.h:88
bv_word_t
uint32_t bv_word_t
Definition:
bvx_environment.h:49
bv_entry_::bv_start
bv_bitnum_t bv_start
Definition:
bitvector_private.h:68
BV_WORDSIZE
#define BV_WORDSIZE
Definition:
bitvector_private.h:42
bv_word_offset
static uint32_t bv_word_offset(bv_bitnum_t bit_number)
Definition:
bitvector_private.h:104
bvx_patnode
#define bvx_patnode
Definition:
bvx_environment.h:14
BV_BITSIZE
#define BV_BITSIZE
Definition:
bitvector_private.h:41
BVX_PATNODE_TO_STRUCT
BVX_PATNODE_TO_STRUCT(bv_patnode_to_bv_entry, bv_entry, bv_ent_node)
bv_bitnum_t
uint32_t bv_bitnum_t
Definition:
bitvector.h:373
contrail
controller
src
vnsw
agent
services
multicast
stubs
bitvector
bitvector_private.h
Generated by
1.8.5