def match_patterns(patterns, data):
"""
Matches patterns of arrays within data, optimizing for memory.
Args:
patterns: A list of array patterns to search for. Each pattern
is a tuple of (start_index, end_index) representing a range
of indices within the data array.
data: The data array to search within.
Returns:
A dictionary where keys are the pattern indices and values are the
corresponding pattern ranges within the data. Returns an empty
dictionary if no patterns are found.
"""
results = {}
data_len = len(data)
for i, pattern in enumerate(patterns):
start, end = pattern
if 0 <= start <= end < data_len:
results[i] = (start, end)
return results
Add your comment