NVBIO
Main Page
Modules
Classes
Examples
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Groups
Pages
nvbio
basic
packed_vector.h
Go to the documentation of this file.
1
/*
2
* nvbio
3
* Copyright (c) 2011-2014, NVIDIA CORPORATION. All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions are met:
7
* * Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* * Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
12
* * Neither the name of the NVIDIA CORPORATION nor the
13
* names of its contributors may be used to endorse or promote products
14
* derived from this software without specific prior written permission.
15
*
16
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
* DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
20
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
*/
27
28
#pragma once
29
30
#include <
nvbio/basic/packedstream.h
>
31
#include <
nvbio/basic/numbers.h
>
32
#include <
nvbio/basic/vector.h
>
33
34
35
namespace
nvbio {
36
39
42
52
template
<
typename
SystemTag, u
int
32 SYMBOL_SIZE_T,
bool
BIG_ENDIAN_T = false,
typename
IndexType = u
int
32>
53
struct
PackedVector
54
{
55
static
const
uint32
SYMBOL_SIZE
= SYMBOL_SIZE_T;
56
static
const
uint32
BIG_ENDIAN
= BIG_ENDIAN_T;
57
58
static
const
uint32
SYMBOLS_PER_WORD
= 32 /
SYMBOL_SIZE
;
59
static
const
uint32
VECTOR_WIDTH
=
SYMBOLS_PER_WORD
;
60
61
typedef
SystemTag
system_tag
;
62
typedef
IndexType
index_type
;
63
64
typedef
typename
nvbio::vector<system_tag,uint32>::pointer
pointer
;
65
typedef
typename
nvbio::vector<system_tag,uint32>::const_pointer
const_pointer
;
66
67
typedef
PackedStream< pointer,uint8,SYMBOL_SIZE,BIG_ENDIAN,IndexType>
stream_type
;
68
typedef
PackedStream<const_pointer,uint8,SYMBOL_SIZE,BIG_ENDIAN,IndexType>
const_stream_type
;
69
typedef
typename
stream_type::iterator
iterator
;
70
typedef
typename
const_stream_type::iterator
const_iterator
;
71
typedef
ForwardPackedStream<const_pointer,uint8,SYMBOL_SIZE,BIG_ENDIAN,IndexType>
forward_iterator
;
72
73
typedef
uint8
value_type
;
74
typedef
PackedStreamRef<stream_type>
reference
;
75
typedef
PackedStreamRef<const_stream_type>
const_reference
;
76
77
typedef
stream_type
plain_view_type
;
78
typedef
const_stream_type
const_plain_view_type
;
79
82
PackedVector
(
const
index_type
size
= 0);
83
86
template
<
typename
other_tag>
87
PackedVector
(
const
PackedVector<other_tag,SYMBOL_SIZE,BIG_ENDIAN,IndexType>
& other) :
88
m_storage
( other.
m_storage
),
m_size
( other.
m_size
) {}
89
92
void
reserve
(
const
index_type
size
);
93
96
void
resize
(
const
index_type
size
);
97
100
void
clear
(
void
);
101
104
index_type
size
()
const
{
return
m_size
; }
105
108
index_type
length
()
const
{
return
m_size
; }
109
110
index_type
capacity
()
const
{
return
m_storage
.size(); }
111
114
iterator
begin
();
115
118
iterator
end
();
119
122
const_iterator
begin
()
const
;
123
126
const_iterator
end
()
const
;
127
130
void
push_back
(
const
uint8
s);
131
133
void
*
addrof
(
const
index_type
i);
134
138
NVBIO_FORCEINLINE
NVBIO_HOST
const
typename
stream_type::symbol_type
operator[]
(
const
index_type
i)
const
139
{
140
const_stream_type
stream
( &
m_storage
[0] );
141
return
stream[i];
142
}
143
147
NVBIO_FORCEINLINE
NVBIO_HOST
typename
stream_type::reference
operator[]
(
const
index_type
i)
148
{
149
stream_type
stream
( &
m_storage
[0] );
150
return
stream[i];
151
}
152
153
nvbio::vector<system_tag,uint32>
m_storage
;
154
index_type
m_size
;
155
};
156
159
template
<
typename
SystemTag, u
int
32 SYMBOL_SIZE_T,
bool
BIG_ENDIAN_T,
typename
IndexType>
160
inline
161
typename
PackedVector<SystemTag,SYMBOL_SIZE_T,BIG_ENDIAN_T,IndexType>::plain_view_type
162
plain_view
(
PackedVector<SystemTag,SYMBOL_SIZE_T,BIG_ENDIAN_T,IndexType>
& vec)
163
{
164
typedef
typename
PackedVector<SystemTag,SYMBOL_SIZE_T,BIG_ENDIAN_T,IndexType>::plain_view_type
stream
;
165
return
stream
( &vec.
m_storage
.front() );
166
}
167
170
template
<
typename
SystemTag, u
int
32 SYMBOL_SIZE_T,
bool
BIG_ENDIAN_T,
typename
IndexType>
171
inline
172
typename
PackedVector<SystemTag,SYMBOL_SIZE_T,BIG_ENDIAN_T,IndexType>::const_plain_view_type
173
plain_view
(
const
PackedVector<SystemTag,SYMBOL_SIZE_T,BIG_ENDIAN_T,IndexType>
& vec)
174
{
175
typedef
typename
PackedVector<SystemTag,SYMBOL_SIZE_T,BIG_ENDIAN_T,IndexType>::const_plain_view_type
stream
;
176
return
stream
( &vec.
m_storage
.front() );
177
}
178
181
182
}
// namespace nvbio
183
184
#include <
nvbio/basic/packed_vector_inl.h
>
Generated on Wed Feb 25 2015 08:32:56 for NVBIO by
1.8.4