Total Image Size from Unique Layers
Problem Statement
Container images share layers by content digest. Given the layers of several images, compute the total on-disk size counting each unique layer digest only once.
Background
A registry stores each layer once, keyed by digest. The disk footprint of a set of images is the sum of sizes over distinct digests, even if many images reference the same layer.
Your Task
def total_disk(images):
- images: list of images, each a list of (digest, size) tuples.
- Return the summed size of unique digests (int).
Input Format
- images (list of lists of (str, int)).
Output Format
- A single int.
Sample
print(total_disk([[("a", 100), ("b", 50)], [("a", 100), ("c", 30)]]))
Output:
180
Example
print(total_disk([[("a", 100), ("b", 50)], [("a", 100), ("c", 30)]]))180
- Identify all unique layer digests across the two images. Image 1 contains layers "a" and "b", while Image 2 contains layers "a" and "c". The distinct set of digests is .
- Determine the size associated with each unique digest. Since each digest maps to a single size, we have: "a" 100, "b" 50, and "c" 30. Note that "a" appears in both images but is counted only once.
- Sum the sizes of these unique layers to find the total disk footprint: .
- The final output is 180
Constraints
- Count each digest once (same digest implies same size).
- Sum sizes of the distinct digests.
- Return an int.