It may be offtopic, but just a hint ...
Remember that your function (s) / data structure is likely to be unsafe for read operations. There is a certain basic thread safety where read operations do not require synchronization. If you are going to store information about how much the reader is reading from your structure, this will make the entire conceptual stream unsafe and a little unnatural to use. Because no one assumes that reading is done in full.
If two threads call it, they will either have to synchronize calls, or your data structure may be in a race state. The problem with this design is that both threads must have access to a common synchronization variable.
I would suggest making two overloaded functions. Both are stateless, but one of them should take a hint iterator where to start the next search / search / search, etc. This, for example, is how Allocator is implemented in STL. You can pass a hint pointer to the allocator (default is 0) to quickly find a new piece of memory.
Yours faithfully,
Hovhannes
source share