Citadel's observability pipeline receives log data that may be too large to load into memory. Given an iterable of log lines and a collection of error patterns, count every occurrence of each pattern in one streaming pass.
Matches may overlap, and a pattern cannot span two log lines. For example, "AAAA" contains three occurrences of "AA". Return a dictionary containing every requested pattern, including patterns with zero matches.
Implement count_error_patterns(lines, patterns).
lines is an iterable of strings. It may be a generator, so do not assume it can be indexed or reread.patterns is a list of distinct, non-empty strings.Use an algorithm that avoids scanning every pattern independently for every line.
def count_error_patterns(lines, patterns):