#include <map>
#include <vector>
{
}
{
}
{
int h = 1;
}
}
return h;
}
};
{
if (!tree) {
return;
}
}
}
{
if (!tree) {
return;
}
}
}
{
if (!node) {
return nullptr;
}
}
{
if (!tree) {
return;
}
} else {
}
}
{
if (!tree) {
return;
}
} else {
}
}
{
top.
append(bottom, Direction::Bottom, Alignment::Center, 5);
top.
append(codeword, Direction::Bottom, Alignment::Center, 5);
return framed(top, 5.0, Color::Blue, Color::Null, 1.0);
}
{
}
};
{
if (nodes.empty()) {
return nullptr;
}
std::priority_queue<Node *, std::vector<Node *>,
NodeGreaterThan> nodeQueue;
for (
const Node & node : nodes) {
}
while (nodeQueue.size() != 1) {
Node * left = nodeQueue.top();
nodeQueue.pop();
Node * right = nodeQueue.top();
nodeQueue.pop();
if (nodeQueue.size()) {
if ((nodeQueue.top()->probability == left->
probability) ||
(nodeQueue.top()->probability == right->
probability)) {
std::cerr << "Warning: Non unique tree because of probability "
}
}
}
return nodeQueue.top();
}
{
std::map<std::string, double> p;
std::vector<Node> n;
delete c;
return result;
}
{
if (!tree) {
return;
}
}
}
{
const float margin = 5;
const double fullWidth = bboxLeft.
width + margin + bboxRight.
width;
{
Point(fullWidth * 0.5, margin * 3),
},
Path::Open, Color::Green, Color::Null, 1.0, LineStyle::SolidStyle, LineCap::RoundCap);
g << left << right << polyline;
box <<
rectangle(labelLeft.
bbox(LineWidthFlag::UseLineWidth).
growed(2), Color::Green, Color::White);
g << box;
box.clear();
box <<
rectangle(labelRight.
bbox(LineWidthFlag::UseLineWidth).
growed(2), Color::Green, Color::White);
g << box;
return g;
}
{
}
return merge(left, right);
}
{
Style::setDefaultLineWidth(0.5);
std::vector<Node> nodes = {
{"X", 0.73},
{"N", 0.08},
{"H", 0.09},
{"W", 0.04},
{"P", 0.03},
{"E", 0.015},
{"Z", 0.015}
};
delete tree;
delete c;
}
Declaration of the Board class.
void extract_leaves(const Node *tree, std::vector< Node > &n)
Definition Huffman.cpp:57
Group LeaveBox(const Node &node)
Definition Huffman.cpp:103
void fill_probabilities(Node *tree, const std::map< std::string, double > &m)
Definition Huffman.cpp:77
Node * canonicalized(Node *tree)
Definition Huffman.cpp:149
void extract_probabilities(const Node *tree, std::map< std::string, double > &m)
Definition Huffman.cpp:45
void fill_codeword(const std::string codeword, Node *tree)
Definition Huffman.cpp:163
Group merge(Group left, Group right)
Definition Huffman.cpp:175
Node * HuffmanTree(const std::vector< Node > &nodes)
Definition Huffman.cpp:123
Node * clone(Node *node)
Definition Huffman.cpp:69
int main(int argc, char *argv[])
Definition arithmetic.cpp:16
Group text()
Definition board_font_text.cpp:17
Path mix(const Path &a, const Path &b, double time)
Interpolate two paths according to a time (0 is a, 1 is b)
Definition Path.cpp:390
Polyline rectangle(double left, double top, double width, double height, Color penColor=Style::defaultPenColor(), Color fillColor=Style::defaultFillColor(), double lineWidth=Style::defaultLineWidth(), const LineStyle lineStyle=Style::defaultLineStyle(), const LineCap cap=Style::defaultLineCap(), const LineJoin join=Style::defaultLineJoin())
Definition Polyline.cpp:569
Group framed(const Shape &shape, double margin=0.0, const Color &penColor=Style::defaultPenColor(), const Color &fillColor=Style::defaultFillColor(), double lineWidth=Style::defaultLineWidth(), LineStyle lineStyle=Style::defaultLineStyle(), int sketchyCount=0)
Surround a shape with a rectangular frame.
Definition Board.cpp:1081
Group boardFontText(Point baselineStart, const std::string &text, double size, Color penColor=Style::defaultPenColor(), double lineWidth=0.0)
Create a text with board's font.
Definition BoardFontText.cpp:320
Class for EPS, FIG or SVG drawings.
Definition Board.h:61
void saveSVG(const char *filename, PageSize size=PageSize::BoundingBox, double margin=0.0, Unit unit=Unit::Millimeter) const
Definition Board.cpp:765
A group of shapes. A group is basically a ShapeList except that when rendered in either an SVG of a F...
Definition Group.h:40
Rect boundingBox(LineWidthFlag) const override
Definition Group.cpp:212
Struct representing a 2D point.
Definition Point.h:42
A polygonal line described by a series of 2D points.
Definition Polyline.h:38
Struct representing a rectangle on the plane.
Definition Rect.h:40
double height
Definition Rect.h:44
double width
Definition Rect.h:43
Rect growed(double margin)
Return the rectangle growed by a given distance (margin) in each direction.
Definition Rect.cpp:135
ShapeList & append(const Shape &shape, Direction direction=Direction::Right, Alignment alignment=Alignment::Center, double margin=0.0, LineWidthFlag lineWidthFlag=UseLineWidth)
Definition ShapeList.cpp:232
Shape & moveCenter(double x, double y, LineWidthFlag lineWidthFlag=IgnoreLineWidth)
Definition Shape.cpp:64
virtual Point center(LineWidthFlag lineWidthFlag=IgnoreLineWidth) const
Definition Shape.cpp:59
Rect bbox(LineWidthFlag) const
Definition Shape.h:332
Definition Huffman.cpp:115
bool operator()(const Node *a, const Node *b)
Definition Huffman.cpp:116
Definition Huffman.cpp:17
int height() const
Definition Huffman.cpp:32
Node * right
Definition Huffman.cpp:22
double probability
Definition Huffman.cpp:19
~Node()
Definition Huffman.cpp:27
Node * left
Definition Huffman.cpp:21
std::string symbol
Definition Huffman.cpp:18
std::string codeword
Definition Huffman.cpp:20