A map would be the simplest way to achieve this.

You could use a vector if the maximum id is not too large. You would have to have a method of indicating which 'slots' held valid entries.

If you go the map route and want maximum speed then try std::tr1::unordered_map. I imagine that the hash function for an unsigned long is pretty simple and fast (probably just uses the value)