updatable_priority_queue
updatable_priority_queue copied to clipboard
The Key is limited as int.
Suppose that I want a unique "std::string name;" as Key, this queue is not work.
That is true. In that case what you probably want to do is first remap your name to an int key:
int new_indexes = 0;
unordered_map<string, int> m;
auto f = m.find(name);
// and for each entry string
int idx; // Will store the remapping
if (f != m.end()) {
idx = f->first;
} else {
idx = new_indexes++;
m[name] = idx;
}
Another alternative if you need this often would be to create a wrapper around the existing updatable_priority_queue structure that does this process transparently (remapping the inputs and outputs on the fly), but I've found it's usually easier and more performant to just remap to ints before running the algorithm.
As explained in the README, this is on purpose that this is not supported in the current structure: otherwise this would have to be a hashmap, making the whole structure much slower (hashing would be called log(n) times for each operation). So in any case, creating another wrapper around it is the most performant.