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