Containers

Containers are data types that contain a set of elements. Banshee uses wrappers for C++ standard library containers like vector, set or map. Aside from different names Banshee containers act exactly like standard library containers.

All available containers:

  • Vector - A sequential list of elements. Fast iteration, slow lookup, slow insertion/deletion (except for the last element).
  • List - A sequential list of elements. Slow iteration, slow lookup, fast insertion/deletion for all elements.
  • Stack - A collection of elements where elements can only be retrieved and inserted in a specific order. Last element inserted is always the first element retrieved.
  • Queue - A collection of elements where elements can only be retrieved and inserted in a specific order. First element inserted is always the first element retrieved.
  • Set - An ordered list of elements. Fast iteration, fast lookup, mediocre insertion/deletion.
  • Map - Same as Set, only each element is represented as a key-value pair, while Set only contains keys.
  • UnorderedSet - Similar to Set it allows fast lookup, but elements aren't sorted. In general offers better performance than Set.
  • UnorderedMap - Same as UnorderedSet, only each element is represented as a key-value pair, while Set only contains keys.

An example with a vector and an unordered map:

int nextUserId = 0;
Vector<String> userNames = { "Sleepy", "Grumpy", "Dopey" };
// Generate IDs for each user and store them in a map for quick lookup.
UnorderedMap<String, int> users;
for(auto& entry : userNames)
users[entry] = nextUserId++;
// Perform lookup to check if user exists
auto iterFind = users.find("Sneezy");
if(iterFind != users.end())
{
// User exists
int userId = iterFind->second;
}