Class ParentMap

Namespace
CHDSharp.Encoder
Assembly
CHDSharpLib.dll

Builds the parent-hunk hash map used to create differential (delta) CHDs. The parent CHD is decompressed once, and every unit-aligned window of its data (one hunk's worth of bytes starting at each unit boundary) is hashed; during encoding, a child hunk whose full-hunk (CRC-16, SHA-1) matches a window is emitted as a CompressionParent reference to that parent unit — mirroring MAME's chd_file_compressor parent walk (chd.cpp: hashes every parent unit window, then matches child hunks against it).

public sealed class ParentMap : IDisposable
Inheritance
ParentMap
Implements
Inherited Members

Remarks

The walk is sequential (the parent's hunks must be decompressed once; each read is cached by the reader). The map itself is read-only after construction, so it is safe to consult from the encoder's single consumer thread during the parallel pipeline.

Constructors

ParentMap(string, uint, uint)

Initializes a new parent map by decompressing and hashing the parent CHD.

public ParentMap(string parentPath, uint hunkBytes, uint unitBytes)

Parameters

parentPath string

Path of the parent CHD file.

hunkBytes uint

The hunk size of the child being created.

unitBytes uint

The unit size of the child being created.

Exceptions

ArgumentException

parentPath is null or the parent's hunk/unit sizes do not match hunkBytes/unitBytes.

IOException

The parent CHD cannot be opened.

Properties

HunkBytes

The hunk size of the parent CHD (equal to the child's).

public uint HunkBytes { get; }

Property Value

uint

HunkCount

The hunk count of the parent CHD.

public uint HunkCount { get; }

Property Value

uint

ParentSha1

The parent's overall SHA-1 (header field), stored in the child's parent-SHA-1 field.

public byte[] ParentSha1 { get; }

Property Value

byte[]

UnitBytes

The unit size of the parent CHD (equal to the child's).

public uint UnitBytes { get; }

Property Value

uint

UnitsPerHunk

The number of units per hunk.

public uint UnitsPerHunk { get; }

Property Value

uint

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

TryGetParentUnit(ushort, string, out uint)

Looks up a child hunk's (CRC-16, SHA-1) in the parent map.

public bool TryGetParentUnit(ushort crc16, string sha1Hex, out uint parentUnit)

Parameters

crc16 ushort

CRC-16 of the child hunk's data.

sha1Hex string

Hexadecimal SHA-1 of the child hunk's data.

parentUnit uint

When true is returned, the parent unit index (0-based, in units) whose data matches the child hunk.

Returns

bool

true if a matching parent unit exists; otherwise false.