Exemplo n.º 1
0
        private static ContentHashWithSizeAndLocations Subtract(ContentHashWithSizeAndLocations left, ContentHashWithSizeAndLocations right)
        {
            Contract.Requires(left.ContentHash == right.ContentHash);
            Contract.Requires(left.Size == -1 || right.Size == -1 || right.Size == left.Size);
            var finalList = (left.Locations ?? Enumerable.Empty <MachineLocation>()).Except(right.Locations ?? Enumerable.Empty <MachineLocation>());

            return(new ContentHashWithSizeAndLocations(left.ContentHash, Math.Max(left.Size, right.Size), finalList.ToList()));
        }
Exemplo n.º 2
0
        private static ContentHashWithSizeAndLocations Merge(ContentHashWithSizeAndLocations left, ContentHashWithSizeAndLocations right)
        {
            Contract.Requires(left.ContentHash == right.ContentHash);
            Contract.Requires(left.Size == -1 || right.Size == -1 || right.Size == left.Size);
            var finalList = (left.Locations ?? Enumerable.Empty <MachineLocation>()).Union(right.Locations ?? Enumerable.Empty <MachineLocation>());

            return(new ContentHashWithSizeAndLocations(left.ContentHash, Math.Max(left.Size, right.Size), finalList.ToList(), ContentLocationEntry.MergeEntries(left.Entry, right.Entry)));
        }
Exemplo n.º 3
0
        private static GetBulkLocationsResult MergeResults(GetBulkLocationsResult left, GetBulkLocationsResult right)
        {
            Contract.Requires(left != null);

            if (right == null || !left.Succeeded)
            {
                return(left);
            }

            if (!right.Succeeded)
            {
                return(right);
            }

            var contentHashInfo = new List <ContentHashWithSizeAndLocations>(left.ContentHashesInfo);

            Contract.Check(left.Count == right.Count)?.Assert($"Can't merge results of different sizes. left.Count is {left.Count}, right.Count is {right.Count}");
            for (int i = 0; i < contentHashInfo.Count; i++)
            {
                contentHashInfo[i] = ContentHashWithSizeAndLocations.Merge(left.ContentHashesInfo[i], right.ContentHashesInfo[i]);
            }

            return(new GetBulkLocationsResult(contentHashInfo));
        }