Skip to content

Commit 273a4cd

Browse files
committed
Adding primitive tree printing for debugging
1 parent ef25fcb commit 273a4cd

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Src/DasherCore/LanguageModelling/PPMLanguageModel.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include "PPMLanguageModel.h"
1010

1111
#include <cstring>
12+
#include <iostream>
13+
#include <iterator>
1214
#include <myassert.h>
1315

1416
using namespace Dasher;
@@ -449,6 +451,19 @@ struct BinaryRecord {
449451
short int m_iSymbol;
450452
};
451453

454+
void CPPMLanguageModel::printTreeRecursive(CPPMnode* node){
455+
std::cout << '>' << std::endl;
456+
for (ChildIterator it = node->children(); it != node->end(); it++) {
457+
std::cout << static_cast<char>('a' + (*it)->sym - 1) << '|' << (*it)->count << std::endl;
458+
printTreeRecursive(*it);
459+
}
460+
std::cout << '<' << std::endl;
461+
}
462+
463+
void CPPMLanguageModel::printTree(){
464+
printTreeRecursive(m_pRoot);
465+
}
466+
452467
bool CPPMLanguageModel::WriteToFile(std::string strFilename) {
453468

454469
std::map<CPPMnode *, int> mapIdx;

Src/DasherCore/LanguageModelling/PPMLanguageModel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,16 @@ namespace Dasher {
143143
public:
144144
CPPMLanguageModel(CSettingsStore* pSettingsStore, int iNumSyms);
145145
virtual void GetProbs(Context context, std::vector < unsigned int >&Probs, int norm, int iUniform) const;
146+
147+
void printTree();
148+
void printTreeRecursive(CPPMnode* node);
146149
protected:
147150
/// Makes a standard CPPMnode, but using a pooled allocator (m_NodeAlloc) - faster!
148151
virtual CPPMnode *makeNode(int sym);
149152

150153
virtual bool WriteToFile(std::string strFilename);
151154
virtual bool ReadFromFile(std::string strFilename);
155+
152156
private:
153157
int NodesAllocated;
154158

0 commit comments

Comments
 (0)