接下來看一下開源的lzf演算法的實現原始碼。
1.定義的全域性字段:
private2.使用liblzf演算法壓縮資料:readonly
long _hashtable = new
long
[hsize];
private
const
uint hlog = 14
;
private
const
uint hsize = (1
<< 14
);
private
const
uint maxlit = (1
<< 5
);
private
const
uint maxoff = (1
<< 13
);
private
const
uint maxref = ((1
<< 8) + (1
<< 3));
///3.///使用liblzf演算法壓縮資料
/// ///
需要壓縮的資料
///要壓縮的資料的長度
///引用將包含壓縮資料的緩衝區
///壓縮緩衝區的長度(應大於輸入緩衝區)
///輸出緩衝區中壓縮歸檔的大小
public
int compress(byte input, int inputlength, byte output, int
outputlength)
len -= 2
; iidx++;
if (len < 7
)
else
output[oidx++] = (byte
)off;
iidx += len - 1
; hval = (uint)(((input[iidx]) << 8) | input[iidx + 1
]); hval = (hval << 8) | input[iidx + 2
]; _hashtable[((hval ^ (hval << 5)) >> (int)(((3 * 8 - hlog)) - hval * 5) & (hsize - 1))] =iidx;
iidx++;
hval = (hval << 8) | input[iidx + 2
]; _hashtable[((hval ^ (hval << 5)) >> (int)(((3 * 8 - hlog)) - hval * 5) & (hsize - 1))] =iidx;
iidx++;
continue
; }
}else
if (iidx ==inputlength)
break
; lit++;
iidx++;
if (lit != maxlit) continue
;
if (oidx + 1 + maxlit >=outputlength)
return0;
output[oidx++] = (byte)(maxlit - 1
); lit = -lit;
dooutput[oidx++] = input[iidx +lit];
while ((++lit) != 0
); }
if (lit == 0) return (int
)oidx;
if (oidx + lit + 1 >=outputlength)
return0;
output[oidx++] = (byte)(lit - 1
); lit = -lit;
dooutput[oidx++] = input[iidx +lit];
while ((++lit) != 0
);
return (int
)oidx;
}
///以上是lzf演算法的**。///使用liblzf演算法解壓縮資料
/// ///
參考資料進行解壓縮
///要解壓縮的資料的長度
///引用包含解壓縮資料的緩衝區
///輸出緩衝區中壓縮歸檔的大小
///返回解壓縮大小
public
int decompress(byte input, int inputlength, byte output, int
outputlength)
dooutput[oidx++] = input[iidx++];
while ((--ctrl) != 0
); }
else
if (reference < 0
)
output[oidx++] = output[reference++];
output[oidx++] = output[reference++];
dooutput[oidx++] = output[reference++];
while ((--len) != 0
); }
}while (iidx
return (int
)oidx;
}
Apple的LZF演算法解析
接下來看一下開源的lzf演算法的實現原始碼。1.定義的全域性字段 private readonly long hashtable new long hsize private const uint hlog 14 private const uint hsize 1 14 private const...
Apple的LZF演算法解析
接下來看一下開源的lzf演算法的實現原始碼。1.定義的全域性字段 private readonly long hashtable new long hsize private const uint hlog 14 private const uint hsize 1 14 private const...
Apple的LZF演算法解析
接下來看一下開源的lzf演算法的實現原始碼。1.定義的全域性字段 private readonly long hashtable new long hsize private const uint hlog 14 private const uint hsize 1 14 private const...