Created
January 7, 2023 01:45
-
-
Save lukaszo/e76cd01caec3cf5482899fe32a287016 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func blockPosition(datastream []byte, size int) (int, error) { | |
block := make([]byte, size) | |
start := 0 | |
count := 1 | |
var duplicateIndex int | |
for i := 1; i < len(datastream); { | |
block = datastream[start : start+count] | |
if count == size { | |
return i, nil | |
} | |
duplicateIndex = bytes.IndexByte(block, datastream[i]) | |
if duplicateIndex == -1 { | |
count += 1 | |
} else { | |
count = count - duplicateIndex | |
start = start + duplicateIndex + 1 | |
} | |
i += 1 | |
} | |
return 0, errors.New("not found") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment