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
I have a slotmap like <FooID, FooV1> and now I'd like to make <FooID, FooV2>, without changing the keys. Is there some way I can do this? I couldn't figure it out. Thanks.
Reacted by Zyansheep, Navid Vahdat and Michael Weiss
Right now there isn't a direct way to do this on a slotmap. You could have the keys allocated by one slotmap and then store the values in a SecondaryMap. You can have multiple SecondaryMaps with the same key, so creating a v2 shouldn't be an issue.
Same requirement here. Though it took a lot of debugging to even notice the source of my problem...
I layout a graph. The layout happens in sequential process steps. In each step I need some shared and some different data.
When I convert the nodes they get new keys. But the edges and other data structure still refer to the old indices. And since the keys are of the same type, this went unnoticed for a while and was really hard to debug, when I eventually noticed it.
Update the references to nodes (the keys) would take a lot of computing time. There usually are much more references to nodes than there are nodes.
I havn't looked into using a SecondaryMap yet. What is the impact of using SecondaryMap on cache locality?
@orlp Using SecondaryMap works well, generally. And the conversion quite easy, too. I have some duplicate data now, but that isn't so bad, and could be remedied, if it proved problematic.
One problem I noted is that when iterating over the secondary map after removing an element from the primary, but not from the secondary, the removed element still is iterated.
One problem I noted is that when iterating over the secondary map after removing an element from the primary, but not from the secondary, the removed element still is iterated.
Yes, a SecondaryMap is completely independent from its primary map. It can re-use slots so old things get deleted automatically eventually if their space is needed, but nothing is guaranteed. If you want them to stay synced you have to perform a delete on a primary map and all secondary maps.
Note that I do think I will implement the following function in slotmap 2.0, when I have the time and energy to make it:
I have a use case for a map function that is not covered by SecondaryMap.
I need to serialize/deserialize a SlotMap<T>, however in my case T is not serializable. Using a map function, I would proceed as follows
serialization: SlotMap<T> -> SlotMap<U> -> Serial where U is serializable/deserializable
deserialization: Serial -> SlotMap<U> -> SlotMap<T>
Using a SecondaryMapfor this use case is not possible, as I cannot implement a Deserialize that would recover the original SlotMap<T> from a SecondaryMap<U>.
@orlp Would you consider a PR that provides the map implementation? Happy to write it.
Activity
orlp commentedon Nov 17, 2021
Right now there isn't a direct way to do this on a slotmap. You could have the keys allocated by one slotmap and then store the values in a
SecondaryMap. You can have multipleSecondaryMaps with the same key, so creating a v2 shouldn't be an issue.NeverGivinUp commentedon Feb 11, 2022
Same requirement here. Though it took a lot of debugging to even notice the source of my problem...
I layout a graph. The layout happens in sequential process steps. In each step I need some shared and some different data.
When I convert the nodes they get new keys. But the edges and other data structure still refer to the old indices. And since the keys are of the same type, this went unnoticed for a while and was really hard to debug, when I eventually noticed it.
Update the references to nodes (the keys) would take a lot of computing time. There usually are much more references to nodes than there are nodes.
I havn't looked into using a
SecondaryMapyet. What is the impact of usingSecondaryMapon cache locality?NeverGivinUp commentedon Feb 28, 2022
@orlp Using
SecondaryMapworks well, generally. And the conversion quite easy, too. I have some duplicate data now, but that isn't so bad, and could be remedied, if it proved problematic.One problem I noted is that when iterating over the secondary map after removing an element from the primary, but not from the secondary, the removed element still is iterated.
orlp commentedon Feb 28, 2022
@NeverGivinUp
Yes, a SecondaryMap is completely independent from its primary map. It can re-use slots so old things get deleted automatically eventually if their space is needed, but nothing is guaranteed. If you want them to stay synced you have to perform a delete on a primary map and all secondary maps.
Note that I do think I will implement the following function in
slotmap2.0, when I have the time and energy to make it:lmondada commentedon Aug 14, 2025
I have a use case for a
mapfunction that is not covered bySecondaryMap.I need to serialize/deserialize a
SlotMap<T>, however in my caseTis not serializable. Using amapfunction, I would proceed as followsSlotMap<T> -> SlotMap<U> -> Serialwhere U is serializable/deserializableSerial -> SlotMap<U> -> SlotMap<T>Using a
SecondaryMapfor this use case is not possible, as I cannot implement aDeserializethat would recover the originalSlotMap<T>from aSecondaryMap<U>.@orlp Would you consider a PR that provides the
mapimplementation? Happy to write it.