Content-Defined Chunking With a Gear Rolling Hash
Last updated: November 29, 2026
Quick Overview
Write a function that splits a byte stream into variable-size chunks using a gear rolling hash, cutting when the hash matches a mask, with minimum and maximum chunk sizes, so that inserting bytes near the start of a file only changes the chunks around the edit.
Pure Storage
November 29, 20260
0
0 solved
Write a function that splits a byte stream into variable-size chunks using a gear rolling hash, cutting when the hash matches a mask, with minimum and maximum chunk sizes, so that inserting bytes near the start of a file only changes the chunks around the edit.
Fixed-size chunking loses almost all deduplication when data shifts by a few bytes, which matters for FlashBlade backup targets and for any variable-block dedup. The interviewer wants you to explain why content-defined boundaries resynchronize and to implement the rolling hash with correct min and max size handling.
What the Interviewer Expects
- Explains why fixed blocks fail on insertions and content-defined cuts recover
- Implements the gear hash update h = (h << 1) + G[byte] with 64-bit masking
- Chooses the mask width from the target average chunk size
- Enforces minimum and maximum sizes and resets the hash at each cut
- Demonstrates that an edit only perturbs nearby chunks
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Why test the high bits of the gear hash rather than the low bits?
- How does normalized chunking (two masks) tighten the size distribution?
- How would you make this fast enough for multiple GB/s per core?
- How do minimum size skipping and maximum size cuts affect dedup ratio?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: bytes, a minimum size, a target average of 2^avg_bits bytes, a maximum size. Output: a list of chunk end offsets covering the input exactly. Boundaries should depend only on local content so th...
High-Level Design
A gear hash keeps a 64-bit state updated by shifting left one bit and adding a random 64-bit constant chosen by the input byte. After the shift, bytes older than 64 positions have been shifted out, so...