internal static void Find <T>( IReadOnlyList <T> values, ChecksumWithChildren checksums, HashSet <Checksum> searchingChecksumsLeft, Dictionary <Checksum, object> result, CancellationToken cancellationToken) { Contract.ThrowIfFalse(values.Count == checksums.Children.Count); for (var i = 0; i < checksums.Children.Count; i++) { cancellationToken.ThrowIfCancellationRequested(); if (searchingChecksumsLeft.Count == 0) { return; } var checksum = (Checksum)checksums.Children[i]; var value = values[i]; if (searchingChecksumsLeft.Remove(checksum)) { result[checksum] = value; } } }
public void SerializeChecksumWithChildren(ChecksumWithChildren checksums, ObjectWriter writer, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var kind = checksums.GetWellKnownSynchronizationKind(); writer.WriteInt32((int)kind); checksums.Checksum.WriteTo(writer); writer.WriteInt32(checksums.Children.Count); foreach (var child in checksums.Children) { switch (child) { case Checksum checksum: writer.WriteByte(ChecksumKind); checksum.WriteTo(writer); continue; case ChecksumCollection checksumCollection: writer.WriteByte(ChecksumWithChildrenKind); SerializeChecksumWithChildren(checksumCollection, writer, cancellationToken); continue; } throw ExceptionUtilities.UnexpectedValue(child); } }
public void SerializeChecksumWithChildren(ChecksumWithChildren checksums, ObjectWriter writer, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); var kind = checksums.GetWellKnownSynchronizationKind(); writer.WriteString(kind); checksums.Checksum.WriteTo(writer); writer.WriteInt32(checksums.Children.Count); foreach (var child in checksums.Children) { var checksum = child as Checksum; if (checksum != null) { writer.WriteByte(ChecksumKind); checksum.WriteTo(writer); continue; } var checksumCollection = child as ChecksumCollection; if (checksumCollection != null) { writer.WriteByte(ChecksumWithChildrenKind); SerializeChecksumWithChildren(checksumCollection, writer, cancellationToken); continue; } throw ExceptionUtilities.UnexpectedValue(child); } }
private static HashSet<Checksum> Flatten(ChecksumWithChildren checksums) { var set = new HashSet<Checksum>(); set.Add(checksums.Checksum); foreach (var child in checksums.Children) { var checksum = child as Checksum; if (checksum != null) { set.Add(checksum); } var collection = child as ChecksumCollection; if (collection != null) { foreach (var item in collection) { set.Add(item); } } } return set; }