Okay, so I chose a queue algo which keeps track of oldest and newest index.
The updated code can be seen here.
Here is a nice teaser snippet
public async Task EnqueueAsync(T item)
{
var last = await _head.GetLastAsync(minEntryCount: 1);
var newestIndex = -1;
var niRes = await last.TryGetMetadata(NEWEST_INDEX);
if (niRes.HasValue)
newestIndex = Convert.ToInt32(niRes.Value);
newestIndex++;
await last.AddValueAsync(newestIndex.ToString(), item);
await _head.SetMetadata(NEWEST_INDEX, newestIndex);
}
The queue maintains FIFO in basic scenarios, but there is still some cases to cover.
This solution has some problems, for example if the queue is never empty so that indices can be reset, but I wanted a working queue. If anyone has a better idea please let us know ![]()
So, now the last unit test of the Queue class (first_in_first_out) is passing.
I added another one to test what happens when we exceed the first MD max count.
Unfortunately, we hit the infamous garbage collection of delegates long before that, and I cannot unit test this specific case now.
I guess I will make sure the queue indices are reset when emptied, as well as complete the api for the dictionary, so that ClearAsync and TryRemoveAsync can be used, before I head over to the bigger challenge of transactions.
Edit: @neo gave some nice tips here for how I could modify the dictionary to use less immutable data writes. I’m considering it, at least as a variant, since one of the use cases I currently have, would potentially be quite wasteful with data storage.