]> hydra-www.ietfng.org Git - instirc/commitdiff
Minor updates to huffgen.pl utility
authornwf <nwf@cs.jhu.edu>
Fri, 29 Aug 2008 20:07:12 +0000 (16:07 -0400)
committernwf <nwf@cs.jhu.edu>
Fri, 29 Aug 2008 20:07:12 +0000 (16:07 -0400)
darcs-hash:20080829200712-4d648-9dd281c4810c541106fb01dbc1772711df2d378b.gz

huffgen.pl

index f639efb839e66e2a8d662a4872621baff73667e1..5a82f59253c75ab6540d08a6d569e0f405eb76d1 100644 (file)
@@ -3,7 +3,7 @@ $Data::Dumper::Indent = 0;
 
 my $DEBUG = 1;
 my $PROGRESS = 1;
-my $NARY=6;
+my $NARY=5;
 
 my %count;
 my %icount;
@@ -18,7 +18,7 @@ while (<>) {
                $totalcount++;
 
                print STDERR " Consumed $totalcount symbols...\r"
-                       if $PROGRESS and ($totalcount % 1000 == 0);
+                       if $PROGRESS and ($totalcount % 10000 == 0);
        }
 }
 
@@ -75,6 +75,10 @@ while (numleft() > 1) {
        my $cv = 0;
        my @cs = ();
 
+    if ( numleft() < $NARY ) {
+        warn "Incomplete toplevel tree with ",numleft()," nodes \n";
+    }
+
        while ($i < $NARY and numleft() > 0) {
                my ($nn, $nv) = @{grabnext()};
 
@@ -92,7 +96,11 @@ while (numleft() > 1) {
 
        print STDERR "GROUPING ($cn)\@$cv\n" if $DEBUG;
 
-       push @secondary, ["($cn)", $cv];
+    if (length $cn == 5) {
+        push @secondary, [" \"$cn\" ", $cv];
+    } else {
+           push @secondary, [" [ $cn ] ", $cv];
+    }
 }
 
 print @{$secondary[0]}[0]."\n";