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  This encoding works on a 4 byte integer, by truncating initial zeros or ones.
39  If the initial (most significant) half byte is 0x0 or 0xf, the number of such
40  halfbytes starting from the most significant is stored in a halfbyte. This initial
41  count is then followed by the rest of the ints halfbytes, in little-endian order.
42  A count halfbyte c of
43 
44  0 <= c <= 8 is interpreted as an initial c 0x0 halfbytes
45  9 <= c <= 15 is interpreted as an initial (c-8) 0xf halfbytes
46 
47  Ex:
48  int c rest
49  0 => 0x8
50  -1 => 0xf 0xf
51  23 => 0x6 0x7 0x1
52  */
53 
54 #ifndef OPENMS_MATH_MISC_MSNUMPRESS_H
55 #define OPENMS_MATH_MISC_MSNUMPRESS_H
56 
57 #include <cstddef>
58 #include <vector>
59 
60 // defines whether to throw an exception when a number cannot be encoded safely
61 // with the given parameters
62 #ifndef MS_NUMPRESS_THROW_ON_OVERFLOW
63 #define MS_NUMPRESS_THROW_ON_OVERFLOW true
64 #endif
65 
66 namespace ms {
67 namespace numpress {
68 
69 namespace MSNumpress {
70 
72  const double *data,
73  size_t dataSize);
74 
95  size_t encodeLinear(
96  const double *data,
97  const size_t dataSize,
98  unsigned char *result,
99  double fixedPoint);
100 
107  void encodeLinear(
108  const std::vector<double> &data,
109  std::vector<unsigned char> &result,
110  double fixedPoint);
111 
126  size_t decodeLinear(
127  const unsigned char *data,
128  const size_t dataSize,
129  double *result);
130 
141  void decodeLinear(
142  const std::vector<unsigned char> &data,
143  std::vector<double> &result);
144 
146 
147 
160  size_t encodeSafe(
161  const double *data,
162  const size_t dataSize,
163  unsigned char *result);
164 
165 
178  size_t decodeSafe(
179  const unsigned char *data,
180  const size_t dataSize,
181  double *result);
182 
184 
198  size_t encodePic(
199  const double *data,
200  const size_t dataSize,
201  unsigned char *result);
202 
209  void encodePic(
210  const std::vector<double> &data,
211  std::vector<unsigned char> &result);
212 
227  size_t decodePic(
228  const unsigned char *data,
229  const size_t dataSize,
230  double *result);
231 
242  void decodePic(
243  const std::vector<unsigned char> &data,
244  std::vector<double> &result);
245 
247 
248 
249  double optimalSlofFixedPoint(
250  const double *data,
251  size_t dataSize);
252 
266  size_t encodeSlof(
267  const double *data,
268  const size_t dataSize,
269  unsigned char *result,
270  double fixedPoint);
271 
278  void encodeSlof(
279  const std::vector<double> &data,
280  std::vector<unsigned char> &result,
281  double fixedPoint);
282 
295  size_t decodeSlof(
296  const unsigned char *data,
297  const size_t dataSize,
298  double *result);
299 
308  void decodeSlof(
309  const std::vector<unsigned char> &data,
310  std::vector<double> &result);
311 
312 } // namespace MSNumpress
313 } // namespace msdata
314 } // namespace pwiz
315 
316 #endif // _MSNUMPRESS_HPP_
double optimalLinearFixedPoint(const double *data, size_t dataSize)
Definition: MSNumpress.h:66
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.0.0 Documentation generated on Sat May 16 2015 16:13:27 using doxygen 1.8.9.1