Skip to main content
gamedev.net
🔒 Locked

Set Data Structure

Started by GDKnight 0 replies 950+ views
Original Post
GDKnight
GDKnight
I was wondering if anyone could explain this structure in more detail. Wikipedia has a brief summary of them. I just can't seem to understand why this is important. Why I would ever use this and when I would come across this? Why wouldn't I just store something in an array list or something why create a set? I guess I need to know also where would you use this, and how would it help in that situation.
GDKnight
nilkn
nilkn
In my experience they aren't particularly useful.

The set structure is rather simple: an object simply is or is not in the set. Order does not play a part. A normal 'set' cannot contain duplicates (inserting the same object more than once won't change the set), and is therefore useful for culling out duplicates in another container. A 'multiset' will store equal objects as the name implies.

Some example uses (courtesy of "C++ for Game Programmers" by Noel Llopis, because I couldn't think of any myself [smile]):

- Keep a set of collision normals so you don't process the same one multiple times.
- Keep a set of objects that you are reading from disk. Those objects are read in date order (older to newer), and newer objects can override older ones. PUtting them in a set as we read them will automatically check whether they already existed and override the old ones.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.