Reformat code

This commit is contained in:
世界
2026-02-08 18:23:42 +08:00
parent f765bf1e3b
commit a86dfc26d1
42 changed files with 163 additions and 98 deletions
@@ -8,7 +8,7 @@ struct EncodedBlock {
let bytes: Int
let checksum: UInt32
// Binary format: degree(4) + indices(4*n) + k(4) + bytes(4) + checksum(4) + data
/// Binary format: degree(4) + indices(4*n) + k(4) + bytes(4) + checksum(4) + data
func toBinary() -> Data {
var result = Data()
@@ -12,19 +12,26 @@ final class LubyTransformDecoder {
private var disposedEncodedBlocks: [Int: [() -> Void]] = [:]
private(set) var meta: EncodedBlock?
var k: Int { meta?.k ?? 0 }
var k: Int {
meta?.k ?? 0
}
var progress: Double {
guard k > 0 else { return 0 }
return Double(decodedCount) / Double(k)
}
var isComplete: Bool { meta != nil && decodedCount == k }
var isComplete: Bool {
meta != nil && decodedCount == k
}
private class BlockWrapper: Hashable {
var block: EncodedBlock
let id = UUID()
init(_ block: EncodedBlock) { self.block = block }
init(_ block: EncodedBlock) {
self.block = block
}
static func == (lhs: BlockWrapper, rhs: BlockWrapper) -> Bool {
lhs.id == rhs.id
@@ -92,7 +92,7 @@ final class LubyTransformEncoder {
)
}
// Ideal Soliton Distribution for degree selection
/// Ideal Soliton Distribution for degree selection
private func getRandomDegree() -> Int {
guard k > 1 else { return k }
var probabilities = [Double](repeating: 0, count: k)