StochHMM
v0.34
Flexible Hidden Markov Model C++ Library and Application
Main Page
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
dynamic_bitset.h
Go to the documentation of this file.
1
//
2
// dynamic_bitset.h
3
// dynamic_bitset
4
//
5
// Created by Paul Lott on 3/1/13.
6
// Copyright (c) 2013 Korf Lab, Genome Center, UC Davis, Davis, CA. All rights reserved.
7
//
8
9
#ifndef __dynamic_bitset__dynamic_bitset__
10
#define __dynamic_bitset__dynamic_bitset__
11
12
#include <iostream>
13
#include <vector>
14
#include <math.h>
15
#include <stdlib.h>
16
#include <stdint.h>
17
#include "
bitwise_ops.h
"
18
19
namespace
StochHMM {
20
21
//!\class dynamic_bitset
22
//! A dynamic bitset class
23
//! Allows the bitset to be set dynamically and manipulated in size
24
//! dynamic_bitset uses 32 bit unsigned integers as the underlying
25
//! datatype.
26
//! Need to implement shifting to right and left
27
//! Note: This dynamic_bitset is read from left to right
28
//! This class can be greatly improved by using SSE optimization
29
//! For portability and time issues: SSE optimization haven't been implemented yet.
30
class
dynamic_bitset
{
31
public
:
32
dynamic_bitset
():
current_size
(0),
buffer
(0),
num_ints
(0){}
33
dynamic_bitset
(
size_t
);
34
dynamic_bitset
(
const
dynamic_bitset
&);
35
dynamic_bitset
(
const
std::string&);
36
dynamic_bitset
(
const
std::vector<bool>&);
37
// dynamic_bitset(std::vector<unsigned char>&);
38
// dynamic_bitset(std::vector<uint16_t>&);
39
// dynamic_bitset(std::vector<uint32_t>&);
40
// dynamic_bitset(std::vector<uint64_t>&);
41
// dynamic_bitset(size_t val, uint16_t*);
42
// dynamic_bitset(size_t val, uint32_t*);
43
// dynamic_bitset(size_t val, uint64_t*);
44
// dynamic_bitset(size_t val, unsigned char*);
45
46
void
resize
(
size_t
);
47
void
reserve
(
size_t
);
48
inline
bool
empty
(){
return
(
current_size
==0) ?
true
:
false
;}
49
void
clear
();
50
51
class
bit_ref
{
52
public
:
53
bit_ref
(uint32_t& v,
size_t
position):
val
(v),
pos
(position){}
54
bit_ref
&
operator=
(
bool
value);
55
bit_ref
&
operator=
(
const
bit_ref
& rhs);
56
57
bit_ref
&
operator|=
(
bool
value);
//OR
58
bit_ref
&
operator&=
(
bool
value);
//AND
59
bit_ref
&
operator^=
(
bool
value);
//XOR
60
bit_ref
&
flip
();
61
bit_ref
&
reset
();
62
63
bool
operator~
()
const
;
64
operator
bool()
const
{
return
(this->
val
>>
pos
) & 1;}
65
private
:
66
uint32_t&
val
;
67
size_t
pos
;
68
};
69
70
bool
operator[]
(
size_t
pos)
const
;
71
bit_ref
operator[]
(
size_t
pos);
72
73
dynamic_bitset
operator&
(
const
dynamic_bitset
& rhs);
74
dynamic_bitset
operator|
(
const
dynamic_bitset
& rhs);
75
dynamic_bitset
operator^
(
const
dynamic_bitset
& rhs);
76
dynamic_bitset
operator~
()
const
;
77
78
dynamic_bitset
&
operator=
(
const
dynamic_bitset
& rhs);
79
dynamic_bitset
&
operator&=
(
const
dynamic_bitset
& rhs);
80
dynamic_bitset
&
operator|=
(
const
dynamic_bitset
& rhs);
81
dynamic_bitset
&
operator^=
(
const
dynamic_bitset
& rhs);
82
dynamic_bitset
&
operator-=
(
const
dynamic_bitset
& rhs);
83
dynamic_bitset
&
operator<<=
(
size_t
n);
84
dynamic_bitset
&
operator>>=
(
size_t
n);
85
dynamic_bitset
operator<<
(
size_t
n);
86
dynamic_bitset
operator>>
(
size_t
n);
87
88
void
insert
(
size_t
pos,
size_t
n);
89
void
erase
(
size_t
pos);
90
91
dynamic_bitset
get_intersection
(
const
dynamic_bitset
& rhs);
92
dynamic_bitset
get_union
(
const
dynamic_bitset
& rhs);
93
dynamic_bitset
get_unique
(
const
dynamic_bitset
& rhs);
94
95
bool
operator==
(
const
dynamic_bitset
& rhs)
const
;
96
bool
operator!=
(
const
dynamic_bitset
& rhs)
const
;
97
98
friend
std::ostream&
operator<<
(std::ostream& ,
const
dynamic_bitset
&);
99
100
inline
size_t
size
(){
return
current_size
;}
101
102
bool
at
(
size_t
pos)
const
;
103
bool
test
(
size_t
pos);
104
105
void
set
(
size_t
pos);
106
void
set
(
size_t
pos,
bool
value);
107
108
void
unset
(
size_t
pos);
109
110
void
flip
();
111
void
flip
(
size_t
pos);
112
113
void
reset
();
114
void
reset
(
size_t
pos);
115
116
bool
any
();
117
bool
none
();
118
119
void
push_back
(
bool
);
120
size_t
count
()
const
;
121
size_t
count_before
(
size_t
)
const
;
122
123
size_t
find_first
()
const
;
124
size_t
find_first
(
size_t
pos)
const
;
125
126
size_t
find_last
()
const
;
127
size_t
find_last
(
size_t
pos)
const
;
128
129
bool
parity
();
130
131
std::string
stringify
()
const
;
132
std::string
stringify_all
()
const
;
133
134
bool
intersects
(
const
dynamic_bitset
& )
const
;
135
136
private
:
137
size_t
buffer
;
138
size_t
current_size
;
139
size_t
num_ints
;
140
//uint32_t* array;
141
std::vector<uint32_t>
array
;
142
143
};
144
145
}
146
#endif
/* defined(__dynamic_bitset__dynamic_bitset__) */
Generated on Tue Jul 30 2013 13:23:11 for StochHMM by
1.8.1