NCBI C++ ToolKit
SeqTable_sparse_index.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: SeqTable_sparse_index.hpp 62037 2014-03-10 16:26:03Z vasilche $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Author: Eugene Vasilchenko
27  *
28  * File Description:
29  * Support for SeqTable-sparse-index ASN.1 type
30  * API to work with different representations of sparse index
31  *
32  * Remark:
33  * This code was originally generated by application DATATOOL
34  * using the following specifications:
35  * 'seqtable.asn'.
36  */
37 
38 /// @file SeqTable_sparse_index.hpp
39 /// User-defined methods of the data storage class.
40 ///
41 /// This file was originally generated by application DATATOOL
42 /// using the following specifications:
43 /// 'seqtable.asn'.
44 ///
45 /// New methods or data members can be added to it if needed.
46 /// See also: SeqTable_sparse_index_.hpp
47 
48 
49 #ifndef OBJECTS_SEQTABLE_SEQTABLE_SPARSE_INDEX_HPP
50 #define OBJECTS_SEQTABLE_SEQTABLE_SPARSE_INDEX_HPP
51 
52 
53 // generated includes
55 
57 
58 // generated classes
59 
60 
62 
63 BEGIN_objects_SCOPE // namespace ncbi::objects::
64 
65 
67 
68 
69 /////////////////////////////////////////////////////////////////////////////
70 // CSeqTable_sparse_index is a class that helps representing columns
71 // that has values only in a subset of rows. So this class virtually tells
72 // if a row has a value and what is the sequential number of the value.
73 // The sequential number is treated as an index of the final row's value
74 // in a separate value array.
75 // There are several possible representations:
76 // 1. indexes
77 // - list of indexes of rows having values
78 // 2. indexes-delta
79 // - deltas between sequential rows having values, and the first element
80 // is the index of the first row with value
81 // 3. bit-set
82 // - bit octet array with one bit per row in ASN.1 order, if a bit is set
83 // it mean this row has a value
84 // 4. bit-set-bvector
85 // - serialized bvector<> instance with total bit size stored separately,
86 // similarly to bit-set if a bit is set it mean this row has a value
88 {
90 public:
91  // constructor
93  // destructor
95 
96  static const size_t kSkipped = size_t(0)-1;
97  static const size_t kInvalidRow = size_t(0)-1;
98 
99  // return number of all represented rows (with or without value)
100  size_t GetSize(void) const;
101 
102  // return index of a value for the argument row
103  // return kSkipped if the row doesn't have value
104  size_t GetIndexAt(size_t row) const;
105 
106  // return true if the row has value
107  bool HasValueAt(size_t row) const;
108 
109  // const_iterator iterates only rows with values
111  public:
113  : m_Row(kInvalidRow),
114  m_ValueIndex(0)
115  {
116  }
117 
119 
120  bool operator==(const const_iterator& iter) const {
121  return m_Row == iter.m_Row;
122  }
123 
124  bool operator!=(const const_iterator& iter) const {
125  return !(*this == iter);
126  }
127 
128  // current bit is always set
129  bool operator*(void) const {
130  return true;
131  }
132 
133  size_t GetRow(void) const {
134  return m_Row;
135  }
136 
137  size_t GetValueIndex(void) const {
138  return m_ValueIndex;
139  }
140 
141  // go to the next set bit
143  m_Row = m_Obj->x_GetNextRowWithValue(m_Row, m_ValueIndex);
144  ++m_ValueIndex;
145  return *this;
146  }
147 
148  protected:
150 
152  size_t row,
153  size_t value_index = 0)
154  : m_Obj(obj),
155  m_Row(row),
156  m_ValueIndex(value_index)
157  {
158  }
159 
160  private:
162  size_t m_Row, m_ValueIndex;
163  };
164 
165  // iterators over rows with values
166  const_iterator begin(void) const {
167  return const_iterator(this, x_GetFirstRowWithValue());
168  }
169  const_iterator end(void) const {
170  return const_iterator();
171  }
172 
173 
174  // change the representation of index
175  void ChangeTo(E_Choice type);
176  void ChangeToIndexes(void);
177  void ChangeToIndexes_delta(void);
178  void ChangeToBit_set(void);
179  void ChangeToBit_set_bvector(void);
180 
181  // Overload base setters to reset extra data fields
182  void Reset(void) {
183  x_ResetCache();
184  Tparent::Reset();
185  }
187  x_ResetCache();
188  return Tparent::SetIndexes();
189  }
191  x_ResetCache();
192  return Tparent::SetIndexes_delta();
193  }
195  x_ResetCache();
196  return Tparent::SetBit_set();
197  }
199  x_ResetCache();
201  }
202 
203  void PostRead(void) {
204  x_ResetCache();
205  }
206 
207 protected:
208  friend class const_iterator;
209 
210  void x_ResetCache(void) {
211  m_Cache.Reset();
212  }
213 
214  // iterator support
215  size_t x_GetFirstRowWithValue(void) const;
216  size_t x_GetNextRowWithValue(size_t row, size_t value_index) const;
217 
218  // bits counting support
219  size_t x_GetBitSetCache(size_t byte_count) const;
220 
221  struct SBitsInfo : public CObject {
222  SBitsInfo(void)
223  : m_BlocksFilled(0),
224  m_CacheBlockIndex(size_t(0)-1)
225  {
226  }
227 
228  // size of byte blocks for bit counting
229  static const size_t kBlockSize;
230 
231  // accumulated bits counts per block of bytes
232  // size = (totalbytes+kBlockSize-1)/kBlockSize
233  // m_Blocks[0] = bits in the 1st block (0..kBlockSize-1)
234  // m_Blocks[1] = bits in first 2 blocks (0..2*kBlockSize-1)
236  // number of calculated entries in m_Block
238 
239  // cached accumulated bit counts per byte within a block
240  // size = kBlockSize
241  // m_CacheBlockInfo[0] = bits in the first byte of cached block
242  // m_CacheBlockInfo[1] = bits in first 2 bytes of cached block
243  // ...
245  // index of the block with cached bit counts (or size_t(-1))
247  };
248 
249  CIndexDeltaSumCache& x_GetDeltaCache(void) const;
250  size_t x_GetDeltaSum(size_t index) const;
251  size_t x_FindDeltaSum(size_t sum) const;
252 
254 
255 private:
256  // Prohibit copy constructor and assignment operator
259 };
260 
261 /////////////////// CSeqTable_sparse_index inline methods
262 
263 // constructor
264 inline
266 {
267 }
268 
269 
270 /////////////////// end of CSeqTable_sparse_index inline methods
271 
272 
274 
275 
276 END_objects_SCOPE // namespace ncbi::objects::
277 
279 
280 
281 #endif // OBJECTS_SEQTABLE_SEQTABLE_SPARSE_INDEX_HPP
Data storage class.
CObject –.
Definition: ncbiobj.hpp:180
DECLARE_OPERATOR_BOOL(m_Row !=kInvalidRow)
const_iterator(const CSeqTable_sparse_index *obj, size_t row, size_t value_index=0)
CConstRef< CSeqTable_sparse_index > m_Obj
bool operator!=(const const_iterator &iter) const
bool operator==(const const_iterator &iter) const
CSeqTable_sparse_index_Base –.
CSeqTable_sparse_index_Base Tparent
CSeqTable_sparse_index(const CSeqTable_sparse_index &value)
TIndexes_delta & SetIndexes_delta(void)
const_iterator end(void) const
void Reset(void)
Reset the whole object.
const_iterator begin(void) const
size_t x_GetFirstRowWithValue(void) const
CSeqTable_sparse_index & operator=(const CSeqTable_sparse_index &value)
TBit_set_bvector & SetBit_set_bvector(void)
char value[7]
Definition: config.c:431
#define NCBISER_HAVE_POST_READ(Class)
Definition: serialbase.hpp:943
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_SEQ_EXPORT
Definition: ncbi_export.h:825
TBit_set_bvector & SetBit_set_bvector(void)
Select the variant.
TBit_set & SetBit_set(void)
Select the variant.
TIndexes_delta & SetIndexes_delta(void)
Select the variant.
TIndexes & SetIndexes(void)
Select the variant.
virtual void Reset(void)
Reset the whole object.
Compressed bitset (entry point to bm.h)
const size_t kInvalidRow
Definition: type.c:6
Modified on Thu Nov 30 04:56:03 2023 by modify_doxy.py rev. 669887