Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
MSNumpress.h
Go to the documentation of this file.
1 /*
2  MSNumpress.hpp
3  johan.teleman@immun.lth.se
4 
5  This distribution goes under the BSD 3-clause license. If you prefer to use Apache
6  version 2.0, that is also available at https://github.com/fickludd/ms-numpress
7  Copyright (c) 2013, Johan Teleman
8  All rights reserved.
9 
10  Redistribution and use in source and binary forms, with or without modification,
11  are permitted provided that the following conditions are met:
12 
13 * Redistributions of source code must retain the above copyright notice, this list
14  of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice, this
16  list of conditions and the following disclaimer in the documentation and/or other
17  materials provided with the distribution.
18 * Neither the name of the Lund University nor the names of its contributors may be
19  used to endorse or promote products derived from this software without specific
20  prior written permission.
21 
22  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
23  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25  SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 /*
33  ==================== encodeInt ====================
34  Some of the encodings described below use a integer compression referred to simply as
35 
36  encodeInt()
37 
38  The algorithm is similar to other variable length integer encodings,
39  such as the SQLite Variable-Length Integers encoding, but it uses half
40  bytes in its encoding procedure.
41 
42  This encoding works on a 4 byte integer, by truncating initial zeros or ones.
43  If the initial (most significant) half byte is 0x0 or 0xf, the number of such
44  halfbytes starting from the most significant is stored in a halfbyte. This initial
45  count is then followed by the rest of the ints halfbytes, in little-endian order.
46  A count halfbyte c of
47 
48  0 <= c <= 8 is interpreted as an initial c 0x0 halfbytes
49  9 <= c <= 15 is interpreted as an initial (c-8) 0xf halfbytes
50 
51  Example:
52 
53  int c rest
54  0 => 0x8
55  -1 => 0xf 0xf
56  2 => 0x7 0x2
57  23 => 0x6 0x7 0x1
58  2047 => 0x5 0xf 0xf 0xf
59 
60  Note that the algorithm returns a char array in which the half bytes are
61  stored in the lower 4 bits of each element. Since the first element is a
62  count half byte, the maximal length of the encoded data is 9 half bytes
63  (1 count half byte + 8 half bytes for a 4-byte integer).
64 
65  */
66 
67 #ifndef OPENMS_MATH_MISC_MSNUMPRESS_H
68 #define OPENMS_MATH_MISC_MSNUMPRESS_H
69 
70 #include <cstddef>
71 #include <vector>
72 
73 // defines whether to throw an exception when a number cannot be encoded safely
74 // with the given parameters
75 #ifndef MS_NUMPRESS_THROW_ON_OVERFLOW
76 #define MS_NUMPRESS_THROW_ON_OVERFLOW true
77 #endif
78 
79 namespace ms {
80 namespace numpress {
81 
82 namespace MSNumpress {
83 
93  const double *data,
94  size_t dataSize);
95 
111  const double *data,
112  size_t dataSize,
113  double mass_acc);
114 
135  size_t encodeLinear(
136  const double *data,
137  const size_t dataSize,
138  unsigned char *result,
139  double fixedPoint);
140 
147  void encodeLinear(
148  const std::vector<double> &data,
149  std::vector<unsigned char> &result,
150  double fixedPoint);
151 
166  size_t decodeLinear(
167  const unsigned char *data,
168  const size_t dataSize,
169  double *result);
170 
181  void decodeLinear(
182  const std::vector<unsigned char> &data,
183  std::vector<double> &result);
184 
186 
187 
200  size_t encodeSafe(
201  const double *data,
202  const size_t dataSize,
203  unsigned char *result);
204 
205 
218  size_t decodeSafe(
219  const unsigned char *data,
220  const size_t dataSize,
221  double *result);
222 
224 
238  size_t encodePic(
239  const double *data,
240  const size_t dataSize,
241  unsigned char *result);
242 
249  void encodePic(
250  const std::vector<double> &data,
251  std::vector<unsigned char> &result);
252 
267  size_t decodePic(
268  const unsigned char *data,
269  const size_t dataSize,
270  double *result);
271 
282  void decodePic(
283  const std::vector<unsigned char> &data,
284  std::vector<double> &result);
285 
287 
288 
289  double optimalSlofFixedPoint(
290  const double *data,
291  size_t dataSize);
292 
306  size_t encodeSlof(
307  const double *data,
308  const size_t dataSize,
309  unsigned char *result,
310  double fixedPoint);
311 
318  void encodeSlof(
319  const std::vector<double> &data,
320  std::vector<unsigned char> &result,
321  double fixedPoint);
322 
335  size_t decodeSlof(
336  const unsigned char *data,
337  const size_t dataSize,
338  double *result);
339 
348  void decodeSlof(
349  const std::vector<unsigned char> &data,
350  std::vector<double> &result);
351 
352 } // namespace MSNumpress
353 } // namespace msdata
354 } // namespace pwiz
355 
356 #endif // _MSNUMPRESS_HPP_
double optimalLinearFixedPoint(const double *data, size_t dataSize)
double optimalLinearFixedPointMass(const double *data, size_t dataSize, double mass_acc)
Definition: MSNumpress.h:79
size_t encodeSafe(const double *data, const size_t dataSize, unsigned char *result)
size_t encodeLinear(const double *data, const size_t dataSize, unsigned char *result, double fixedPoint)
size_t decodeSlof(const unsigned char *data, const size_t dataSize, double *result)
size_t encodePic(const double *data, const size_t dataSize, unsigned char *result)
size_t decodePic(const unsigned char *data, const size_t dataSize, double *result)
size_t encodeSlof(const double *data, const size_t dataSize, unsigned char *result, double fixedPoint)
size_t decodeLinear(const unsigned char *data, const size_t dataSize, double *result)
double optimalSlofFixedPoint(const double *data, size_t dataSize)
size_t decodeSafe(const unsigned char *data, const size_t dataSize, double *result)

OpenMS / TOPP release 2.3.0 Documentation generated on Tue Jan 9 2018 18:22:02 using doxygen 1.8.13