I was trying to write an ordered map, which will work like a frequency table. I thought it would be a good addition because ordered_set doesn't support duplicate entries very well.
Here's some code I wrote:
Basically, it changes the update policy to take the frequencies of the keys into account when calculating find_by_order and order_of_key.
However, in the end. I found that this wouldn't work. The tree in pb_ds was implemented only to update the internal data of the node when the structure surrounding that node has changed (nodes shifted), which would only happen when a node is added or deleted. Additionally the structure puts in the key first, operates on the key, then puts in the value.
That means if I change the value (frequency of key), then call find_by_order, the answer will be completely wrong because the internal data didn't update. There's also times where I inserted key value pairs and it didn't update my frequency into the internal data, resulting in wrong answers.
So in the end I figured it wouldn't work. It was a fairly fruitless exploration for me. But at least I found some good links, so if you are interested in PBDS, here they are:
https://ideone.com/jOxlgl (an example of custom defined operator)
https://ideone.com/JlJ86R (print tree)
A few useful blogs:
https://codeforces.me/blog/entry/11080 (basics)
https://codeforces.me/blog/entry/13279 (creating custom policies, tutorial-ish)
https://codeforces.me/blog/entry/110677 (sum of segment)
https://neveropen.tech/interval-tree-using-gnu-tree-based-container/
GCC documentation? https://gcc.gnu.org/onlinedocs/libstdc++/manual/policy_data_structures_design.html#pbds.design.container.tree
Hopefully this is helpful if you're interested in learning about PBDS as well.








Auto comment: topic has been updated by Brackets12 (previous revision, new revision, compare).