0001 void generateCT //通过遍历获取各字符的编码 0002 ( Bitmap* code, int length, PFCTable* table, BinNodePosi<char> v ) { 0003 if ( IsLeaf ( *v ) ) //若是叶节点 0004 { table->put ( v->data, code->bits2string ( length ) ); return; } 0005 if ( HasLChild ( *v ) ) //Left = 0 0006 { code->clear ( length ); generateCT ( code, length + 1, table, v->lc ); } 0007 if ( HasRChild ( *v ) ) //right = 1 0008 { code->set ( length ); generateCT ( code, length + 1, table, v->rc ); } 0009 } 0010 0011 PFCTable* generateTable ( PFCTree* tree ) { //构造PFC编码表 0012 PFCTable* table = new PFCTable; //创建以Skiplist实现的编码表 0013 Bitmap* code = new Bitmap; //用于记录RPS的位图 0014 generateCT ( code, 0, table, tree->root() ); //遍历以获取各字符(叶节点)的RPS 0015 release ( code ); return table; //释放编码位图,返回编码表 0016 } //release()负责释放复杂结构,与算法无直接关系,具体实现详见代码包