Chinaunix首页 | 论坛 | 博客
  • 博客访问: 905523
  • 博文数量: 201
  • 博客积分: 8078
  • 博客等级: 中将
  • 技术积分: 2162
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-20 17:22
文章分类

全部博文(201)

文章存档

2013年(3)

2012年(11)

2011年(34)

2010年(25)

2009年(51)

2008年(77)

分类: WINDOWS

2010-03-25 22:39:59

将个人原来写的LZW压缩算法实现作了以下修改,使用一个89M的FLV视频测试,惊奇的发现速度又原来的1分25秒 变成了 12 秒。的确快了不少,不过这种优化手段要看场合使用,否则代码很难看,到时维护的时候都不知道如何死法。

static int test_mask[32] = {
       1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80,
    0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000, 0x4000, 0x8000,
    0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000, 0x800000,
    0x1000000, 0x2000000, 0x4000000, 0x8000000, 0x10000000, 0x20000000, 0x40000000, 0x80000000
};

static int __dictbl_test[32 * 1024];
static short __dictbl[256 * 4096];

inline void restart()
{
    __bitcnt = 9;
    __dicode = 256 + 2;
    memset(__dictbl_test, 0, sizeof(__dictbl_test));
}

inline int find(int prefix, int code)
{
    int key = (prefix << 8) | code;
    if (__dictbl_test[key >> 5] &
               test_mask[key & 0x1F])
        return __dictbl[key];
    return -1;
}

inline int update(int prefix, int code)
{
    int key = (prefix << 8) | code;
    __dictbl[key] = __dicode++;
    __dictbl_test[key >> 5] |= test_mask[key & 0x1F];
    return __dicode;
}

阅读(762) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~