Skip to content

Instantly share code, notes, and snippets.

@avonwyss
avonwyss / CircularBuffer.cs
Created December 16, 2022 23:16
Async circular buffer with lookback and load-on-demand
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace bsn.Har.Multipart {
public class CircularBuffer<T>: IAsyncEnumerator<T> {
private readonly Func<T[], int, int, CancellationToken, Task<int>> fillBufferAsync;
private readonly T[] buffer;
private int head;
@avonwyss
avonwyss / IKmpMatcher.cs
Created December 16, 2022 23:12
Knuth-Morris-Pratt Pattern Matching
namespace bsn.Har.Multipart {
public interface IKmpMatcher<in T> {
void Reset(int patternPosition = 0);
bool Next(T value);
int Index {
get;
}
}