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

Go to the SVN repository for this file.

1 /* $Id: delta_cache.hpp 66087 2015-01-29 19: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  */
27 
28 #ifndef OBJECTS_SEQTABLE_IMPL_DELTA_CACHE
29 #define OBJECTS_SEQTABLE_IMPL_DELTA_CACHE
30 
31 #include <corelib/ncbiobj.hpp>
32 
34 
35 BEGIN_objects_SCOPE // namespace ncbi::objects::
36 
37 
38 // delta accumulation support
40 {
41 public:
42  virtual ~CIntDeltaSumCache(void);
43 
45 
46  virtual Int4 GetDeltaSum4(const TDeltas& deltas,
47  size_t index);
48  virtual Int8 GetDeltaSum8(const TDeltas& deltas,
49  size_t index);
50 };
51 
52 
53 // delta accumulation support
55 {
56 public:
57  CInt4DeltaSumCache(size_t size); // size of deltas array
58  ~CInt4DeltaSumCache(void);
59 
60  typedef Int4 TValue;
61 
62  TValue GetDeltaSum4(const TDeltas& deltas,
63  size_t index);
64 
65 protected:
66  TValue x_GetDeltaSum2(const TDeltas& deltas,
67  size_t block_index,
68  size_t block_offset);
69 
70  // size of blocks of deltas for accumulation
71  static const size_t kBlockSize;
72 
73  // accumulated deltas for each block
74  // size = (totaldeltas+kBlockSize-1)/kBlockSize
75  // m_Blocks[0] = sum of deltas in the 1st block (0..kBlockSize-1)
76  // m_Blocks[1] = sum of deltas in first 2 blocks (0..2*kBlockSize-1)
78  // number of calculated entries in m_Block
80 
81  // cached accumulated sums per delta within a block
82  // size = kBlockSize
83  // m_CacheBlockInfo[0] = sum of the first delta of cached block
84  // m_CacheBlockInfo[1] = sum of first 2 deltas of cached block
85  // ...
87  // index of the block with cached sums (or size_t(-1))
89 };
90 
91 
92 // delta accumulation support
94 {
95 public:
96  CInt8DeltaSumCache(size_t size); // size of deltas array
97  ~CInt8DeltaSumCache(void);
98 
99  typedef Int8 TValue;
100 
101  TValue GetDeltaSum8(const TDeltas& deltas,
102  size_t index);
103 
104 protected:
105  TValue x_GetDeltaSum2(const TDeltas& deltas,
106  size_t block_index,
107  size_t block_offset);
108 
109  // size of blocks of deltas for accumulation
110  static const size_t kBlockSize;
111 
112  // accumulated deltas for each block
113  // size = (totaldeltas+kBlockSize-1)/kBlockSize
114  // m_Blocks[0] = sum of deltas in the 1st block (0..kBlockSize-1)
115  // m_Blocks[1] = sum of deltas in first 2 blocks (0..2*kBlockSize-1)
117  // number of calculated entries in m_Block
119 
120  // cached accumulated sums per delta within a block
121  // size = kBlockSize
122  // m_CacheBlockInfo[0] = sum of the first delta of cached block
123  // m_CacheBlockInfo[1] = sum of first 2 deltas of cached block
124  // ...
126  // index of the block with cached sums (or size_t(-1))
128 };
129 
130 
131 // delta accumulation support
133 {
134 public:
135  CIndexDeltaSumCache(size_t size); // size of deltas array
136  ~CIndexDeltaSumCache(void);
137 
139  typedef size_t TValue;
140 
141  TValue GetDeltaSum(const TDeltas& deltas,
142  size_t index);
143  size_t FindDeltaSum(const TDeltas& deltas,
144  TValue find_sum);
145 
146 protected:
147  TValue x_GetDeltaSum2(const TDeltas& deltas,
148  size_t block_index,
149  size_t block_offset);
150  size_t x_FindDeltaSum2(const TDeltas& deltas,
151  size_t block_index,
152  TValue find_sum);
153 
154  // size of blocks of deltas for accumulation
155  static const size_t kBlockSize;
156 
157  // special values returned from FindDeltaSum()
158  static const size_t kInvalidRow;
159  static const size_t kBlockTooLow;
160 
161  // accumulated deltas for each block
162  // size = (totaldeltas+kBlockSize-1)/kBlockSize
163  // m_Blocks[0] = sum of deltas in the 1st block (0..kBlockSize-1)
164  // m_Blocks[1] = sum of deltas in first 2 blocks (0..2*kBlockSize-1)
166  // number of calculated entries in m_Block
168 
169  // cached accumulated sums per delta within a block
170  // size = kBlockSize
171  // m_CacheBlockInfo[0] = sum of the first delta of cached block
172  // m_CacheBlockInfo[1] = sum of first 2 deltas of cached block
173  // ...
175  // index of the block with cached sums (or size_t(-1))
177 };
178 
179 
180 END_objects_SCOPE // namespace ncbi::objects::
181 
183 
184 
185 #endif // OBJECTS_SEQTABLE_IMPL_DELTA_CACHE
static const size_t kBlockSize
CSeqTable_sparse_index_Base::TIndexes_delta TDeltas
static const size_t kInvalidRow
AutoArray< TValue > m_CacheBlockInfo
static const size_t kBlockTooLow
AutoArray< TValue > m_Blocks
static const size_t kBlockSize
Definition: delta_cache.hpp:71
AutoArray< TValue > m_CacheBlockInfo
Definition: delta_cache.hpp:86
AutoArray< TValue > m_Blocks
Definition: delta_cache.hpp:77
AutoArray< TValue > m_Blocks
AutoArray< TValue > m_CacheBlockInfo
static const size_t kBlockSize
CSeqTable_multi_data TDeltas
Definition: delta_cache.hpp:44
CObject –.
Definition: ncbiobj.hpp:180
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
int64_t Int8
8-byte (64-bit) signed integer
Definition: ncbitype.h:104
#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
const struct ncbi::grid::netcache::search::fields::SIZE size
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
Modified on Mon Dec 11 02:34:53 2023 by modify_doxy.py rev. 669887