NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
31 #include <nvbio/basic/numbers.h>
32 #include <nvbio/basic/vector.h>
33 
34 
35 namespace nvbio {
36 
39 
42 
52 template <typename SystemTag, uint32 SYMBOL_SIZE_T, bool BIG_ENDIAN_T = false, typename IndexType = uint32>
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;
60 
61  typedef SystemTag system_tag;
62  typedef IndexType index_type;
63 
66 
69  typedef typename stream_type::iterator iterator;
72 
73  typedef uint8 value_type;
76 
79 
82  PackedVector(const index_type size = 0);
83 
86  template <typename other_tag>
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 
139  {
141  return stream[i];
142  }
143 
148  {
150  return stream[i];
151  }
152 
155 };
156 
159 template <typename SystemTag, uint32 SYMBOL_SIZE_T, bool BIG_ENDIAN_T, typename IndexType>
160 inline
163 {
165  return stream( &vec.m_storage.front() );
166 }
167 
170 template <typename SystemTag, uint32 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
174 {
176  return stream( &vec.m_storage.front() );
177 }
178 
181 
182 } // namespace nvbio
183