35 throw std::runtime_error(
36 "Error in Huffmantree::makeTree : Pointer to Events not set!");
47 std::priority_queue<huffmanNode<T> *, std::vector<huffmanNode<T> *>,
51 htree = std::vector<huffmanNode<T>>(
54 auto comp2 = [](T *e1, T *e2) {
return e1->getValue() > e2->getValue(); };
55 std::priority_queue<T *, std::vector<T *>,
decltype(comp2)> eventQueue(
59 Index firstEmptyFieldIndex = 0;
64 while (eventQueue.size() > 1) {
65 htree[firstEmptyFieldIndex].isOnLastLevel =
true;
66 htree[firstEmptyFieldIndex].leftLeaf = eventQueue.top();
68 htree[firstEmptyFieldIndex].rightLeaf = eventQueue.top();
70 htree[firstEmptyFieldIndex].probability =
71 (
htree[firstEmptyFieldIndex].leftLeaf->getValue() +
72 htree[firstEmptyFieldIndex].rightLeaf->getValue()) /
74 queue.push(&(
htree[firstEmptyFieldIndex]));
75 firstEmptyFieldIndex++;
77 if (!eventQueue.empty()) {
78 htree[firstEmptyFieldIndex].isOnLastLevel =
true;
79 htree[firstEmptyFieldIndex].rightLeaf = eventQueue.top();
80 htree[firstEmptyFieldIndex].leftLeaf = eventQueue.top();
81 htree[firstEmptyFieldIndex].probability =
83 queue.push(&(
htree[firstEmptyFieldIndex]));
84 firstEmptyFieldIndex++;
92 while (queue.size() > 1) {
99 htree[firstEmptyFieldIndex].leftChild = h1;
101 queue.push(&(
htree[firstEmptyFieldIndex]));
102 firstEmptyFieldIndex++;