Huffman编码的速度问题,一定给分

qiaomuf 2007-02-05 10:26:15
我已经将huffman编码做好了,可是耗时很多。我想问一下理想的huffman编码速率大概是多少呢?在现在的一般的pc上,能达到多少Kb/s呢?请高手给我一个优化程序的方向,谢谢了
...全文
300 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiaomuf 2007-02-06
  • 打赏
  • 举报
回复
这段代码是程序中最耗时的部分
dis = new DataInputStream(new BufferedInputStream(new FileInputStream(targetFile)));
dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(saveFile)));
writeInfo();
int pack=0;
int packLeft=32;
int in;
NodeItem item;
for(long i=0;i<targetFile.length();i++){
in=dis.readByte()+128;
item=table[in/16][in%16];
if(item.length<=packLeft){
packLeft-=item.length;
pack=(pack<<item.length)|item.code;
if(packLeft==0){
dos.writeInt(pack);
packLeft=32;
}
}
else{
pack<<=packLeft;
int temp=item.code;
temp>>>=item.length-packLeft;
pack|=temp;
dos.writeInt(pack);
pack=0;
pack|=item.code;
packLeft=32-(item.length-packLeft);
}
}
item是这个类的一个对象
package datastructure;

public class NodeItem {

public int code;
public byte length;
public int freq;
public byte ch;
public NodeItem(int code,byte length,byte c){
this.code=code;
this.length=length;
ch=c;
}
public NodeItem(int f){
freq=f;
}
public NodeItem(byte c,int f){
freq=f;
ch=c;
}
public int key() {
return freq;
}

}
huffman树已经建好
table是16*16的二维数组,存放NodeItem的对象
每一个字节都会被映射到数组中
Homers 2007-02-06
  • 打赏
  • 举报
回复
能否看看你的编码.

33,028

社区成员

发帖
与我相关
我的任务
社区描述
数据结构与算法相关内容讨论专区
社区管理员
  • 数据结构与算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧