Jump to content
  • Advertisement
Sign in to follow this  
SeiryuEnder

Converting set to multiset

This topic is 2268 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have written a set class which acts similarly to the STL set class.
Everything functions properly there.
I am now trying to convert this set class into a multiset.

A set class essentially stores its data as a sorted binary tree.
In order to make this a multiset I assume I just insert duplicate key/value pairs left or right and rebalance the tree.

However, I don't really like to assume things, and I'm not sure about what types of limitations this could impose.
Should I instead make a container in each node or a separate nested node list for identical keys?

For instance, structure with a nested node list:
................A
...........B.......C
........../.|.\...../.|.\
........D.E.F.G.H.I
............|.........|
............J........K

Based on simple sorting:
.................A
...........B.........C
........../...\....../...\
........E....F..H.....I
......./........./
.....J........K
..../......../
..D......G

Where the keys for BEJ are the same, and CHK are the same.

Anyone done something similar? Thoughts on the fastest/best way to implement?

It seems to me that adding a nested node list imposes a pretty significant memory overhead (as nodes without duplicate keys will contain a useless pointer) but will be faster to insert while the simple sorting method will be more memory efficient but take longer to insert.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!