You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
yeah, just to elaborate a bit - and this may be two separate issues:
one use-case is exactly as the title says, something like a Set.. it's not that bad to just use Map<Foo, ()>, it could almost work just like a type alias.
the other use-case is a bit trickier, where I want a list with a dynamic key. This is probably solved with Deque::new_dyn, but that's a relatively recent addition and I haven't had the pleasure of needing it hands-on yet :)
Specifically, for the "list with a dynamic key" problem, without Deque::new_dyn, I'd solve it using a composite key and a prefix, e.g.: Map<(Foo, Bar), ()>. Then the "bars for a given foo" can be iterated over via .prefix(foo).keys(...). It works perfectly fine, but it's a bit odd.
the other use-case is a bit trickier, where I want a list with a dynamic key
Ah, right. For this one, I have a feeling we're already good. storey's version of this would be something like Map<Foo, Column<Bar>>. The Map handles dynamic keys of type Foo, and then Column is a bit like a list, only every entry is indexed with u32.
If the column isn't right, it should be fairly easy to implement some other list-like collection in storey, and then plug it into the map.
nice! so just to expand on the use-case a bit - in case this helps:
where i've needed it, it's usually just a dynamic list, and so Column with an index sounds like it covers it completely
but sometimes it's not exactly a list by index, but rather something else... for a made-up example, consider NFTs where TokenId is not numeric but some other string that's created outside of the contracts for some reason.
so TOKENS_PER_OWNER = Map<Addr, Column(TokenId)> could work, but the index isn't something that would really be used - i.e. I'd want to be able to remove an item by (Addr, TokenId) without knowing the internal index
Also, since it's a Map I assume all the usual range/keys stuff just works- but just to make sure, it's important to be able to paginate and in both directions (both Ascending and Descending)
@dakom mentioned he'd sometimes see usage of the
Map
where the value is()
, and the last key component is the actual value.The text was updated successfully, but these errors were encountered: