Sunday, October 28, 2018

Simple graph display

///////  Make a B tree formatted 2-d onto a string
void descend(PNode o,int width, int line ,char* str) {
 if(!o)
  return;
 int_str(str+width/2,o->count);  // place value into string
 descend(o->left,width/2,line,str+line);
 descend(o->right,width/2,line,str+line+width/2);
 } 
And here is the outpu which displays ther count.  Each parent totals its left and right siblings:
                                 81                             
                 29                              52             
         13              16              26              26     
      5       8       8       8                                 
    2   3   4   4   4   4   4   4                               
                                 2                              
                         1     1                                
                                                                
   

Simple enough, fill the string as if it were a console screen, then print it out line by line. I prefill a very long string with space. Then, given the line size, I can put exactly that many characters per line.

I wrote up a simple Huffman encoder, and I need to see the graph format, came up with this nifty plan.  I am running values from the tanhm function into the huffman, and scaling, then truncating the value to see how well I can fine tune the tree encoding graph height and balance. Pit boss research.

My algorithm followed the Wiki description exactly. In the set of symbols input, I create a 'Node' for the symbol and the number of times used. The same symbol does not appear twice.  That is where I scale and truncat floating pint values, I can adjust the coincidence frequency.

Once the values ae bubble sorted by count, then I can pop off the top new, least likely values, and pin them to a parent, which is pushed, and sorted. Each time I do this the stack size drops until iot is zero.

Then I need an easy visual, and just formatting a string as if it were a line by line console is simple.  I like the idea of having a large string holding a prepared console output, line by line. I can get 80% of the visual I need with 5% of the set up and run.

No comments: