-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nested containers with different sizes #111
Comments
I think the problem you are having is that the size of the container is a template parameter, which makes it part of the type information. The map has to use the same type for all values however. So you either need a different container that does not have the size data in its type or I think you’ll need to do something like your dummy data idea. |
Or, like you said, this library could allow you to have a map of size n but allow you to provide less than n keys in the constructor. |
@peter-moran Thanks Peter, Yes, this is how I understand it. Interestingly, we can have a This looks like a (historical) limitation of C++ type system and/or of the established constructor function signatures in the standard library (which It might be a fun exercise to try to use for map values a frozen::string<frozen::string> string_of_strings =
{"ABC", "DEF", "GHI"}; Alternatively, could the namespace frozen {
template <typename Key, size_t Size>
class set<Key, Size>: public unsized_set<Key> {};
}
frozen::map<frozen::string, frozen::unsized_set<frozen::string>, 2> = {
{"one", frozen::set<frozen::string, 1>{"A"}},
{"two", frozen::set<frozen::string, 2>{"B", "C"}},
};
|
Consider this:
Note: your spans are so small, that linear search inside is faster than anything else. |
FYI: this looks like a more generic problem of a part that I'm trying to address with my feat/zero-reloc-string-containers branch (for which #158 is preparation). I.e. I'm dealing with strings of different lengths which are essentially "containers" (arrays) of different sizes with a specific I'm storing two things there to store a two-level array of arrays
When sorting only the elements in the "index" array are swapped. Iterators are proxy iterators that, when dereferenced, return a non-reference In principal the same is possible to generalize away from strings by making the zero-termination optional and providing a conversion to Your example however isn't just storing plain arrays but nesting frozen data structures inside others. While probably possible, that would definitely require some more invasive changes than my implementation for the simple |
I would like nested containers to have different sizes (all known at compile time). Is this possible?
For example, consider this map of sets:
And it's usage:
As you see, sets inside the map have different length.
This currently won't compile:
I thought, if sets really need to be of the same size, then maybe we could fill them with some dummy values, for example
"?"
:I can handle these dummy values in userspace and make sure I never search for the
"?"
in these sets, but from inside the library it can probably be handled more efficiently?Application: reverse translation in biology. I need a lookup table to find a set of possible triplets (value of the map) for a given aminoacid (key of the map). The sets are at most 6 elements. This table is fundamental to biology and never changes, so runtime initialization would be certainly wasteful.
Sets can also be arrays, I guess. They are very small anyway.
Any other ideas on how this can be implemented without runtime initialization and associated static initialization order fiasco etc.?
The text was updated successfully, but these errors were encountered: