Content-defined chunking, rolling fingerprints, and deduplication for MoonBit.
本项目只提供非密码学指纹,不用于签名、口令存储或安全认证。
///|
test {
let bytes = ascii_bytes("alpha-beta-gamma-alpha-beta-gamma-alpha-beta-gamma")
let config = CdcConfig::new(
8, // 最小分块
16, // 目标平均分块
32, // 最大分块
4, // 滚动窗口
)
let chunks = content_defined_chunks(bytes, config)
let summary = summarize_cdc(chunks)
assert_eq(summary.bytes, bytes.length())
assert_true(summary.chunks > 0)
}///|
test {
let hashes = window_hashes([1, 2, 3, 4, 5], 3, base=31, modulo=1009)
assert_eq(hashes.length(), 3)
}///|
let config = CdcConfig::new(8, 16, 32, 4)
///|
let stream = CdcStream::new(config)
///|
let completed = stream.push(ascii_bytes("first network packet"))
///|
let final_chunks = stream.finish()
///|
let missing = missing_fixed_chunks(
ascii_bytes("alpha-beta-gamma"),
ascii_bytes("alpha-beta"),
4,
)moon check --target all
moon test --target wasm
moon run cmd/main
moon run cmd/benchpub(all) struct CdcSummary {
bytes : Int
chunks : Int
min_chunk : Int
max_chunk : Int
average_chunk : Double
} derive(Debug)pub(all) struct ManifestEntry {
start : Int
length : Int
fingerprint : DualFingerprint
} derive(Debug)fn missing_fixed_chunks(source : Array[Int], destination : Array[Int], chunk_size : Int) -> Array[ChunkFingerprint]fn verified_chunk_matches(left : Array[Int], left_chunks : Array[ChunkFingerprint], right : Array[Int], right_chunks : Array[ChunkFingerprint]) -> Array[VerifiedChunkMatch]fn verified_fixed_chunk_matches(left : Array[Int], right : Array[Int], chunk_size : Int) -> Array[VerifiedChunkMatch]Content-defined chunking, rolling fingerprints, and deduplication for MoonBit.