clockUtils  1.1
HuffmanBase.h
Go to the documentation of this file.
1 /*
2  * clockUtils
3  * Copyright (2015) Michael Baer, Daniel Bonrath, All rights reserved.
4  *
5  * This file is part of clockUtils; clockUtils is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
25 #ifndef __CLOCKUTILS_COMPRESSION_ALGORITHM_HUFFMANBASE_H__
26 #define __CLOCKUTILS_COMPRESSION_ALGORITHM_HUFFMANBASE_H__
27 
28 #include <memory>
29 #include <string>
30 #include <vector>
31 
33 
34 namespace clockUtils {
35 
36  enum class ClockError;
37 
38 namespace compression {
39 namespace algorithm {
40 
45  class HuffmanBase {
46  protected:
51  typedef uint32_t len_t;
52 
57  struct Node {
58  len_t value;
59  uint8_t c;
60  std::shared_ptr<Node> left = nullptr;
61  std::shared_ptr<Node> right = nullptr;
62  };
63 
69  static std::shared_ptr<Node> buildTree(const std::vector<uint8_t> & header);
70 
77  static void generateMapping(const std::shared_ptr<Node> & node, const std::vector<bool> & bitSeq, std::vector<std::vector<bool>> & mapping);
78 
86  static ClockError getChar(const std::string & compressed, const std::shared_ptr<Node> & root, len_t length, std::string & result);
87  };
88 
89 } /* namespace algorithm */
90 } /* namespace compression */
91 } /* namespace clockUtils */
92 
93 #endif /* __CLOCKUTILS_COMPRESSION_ALGORITHM_HUFFMANBASE_H__ */
94 
static std::shared_ptr< Node > buildTree(const std::vector< uint8_t > &header)
creates a Huffman tree with given list of probabilities header must have size 256 and values have to ...
static ClockError getChar(const std::string &compressed, const std::shared_ptr< Node > &root, len_t length, std::string &result)
converts bit sequence to the real character
uint32_t len_t
type that should be used as the &#39;length&#39; counter This controls the size of the header, the maximum string length etc.
Definition: HuffmanBase.h:51
static void generateMapping(const std::shared_ptr< Node > &node, const std::vector< bool > &bitSeq, std::vector< std::vector< bool >> &mapping)
constructs a mapping from character to a bit sequence
represents a node in the probability tree if left and right are both nullptr this node is a leave and...
Definition: HuffmanBase.h:57
base class for Huffman compression contains common methods and helper structures
Definition: HuffmanBase.h:45
ClockError
Definition: errors.h:30