0

I am implementing a Max Binary Heap for a problem where I have a lot of servers. When a request occurs, the server with max current capacity will be allocated to serve and this is the reason why binary heap is used.

What I need to know is that, whenever I serve to a request, which server was allocated. I know it's the 0th element in heap but which server was the 0th element in binary heap? Server numbers are integers by the way. For example: I should be able to say "Server no 33 was allocated".

meliksahturker
  • 922
  • 2
  • 11
  • 20
  • *"...which server was the 0th element in binary heap?"* - How could *we* know ? We can't answer this, as we have no way of knowing how you track/maintain your id's for your servers. Chances are, wherever you're keeping a server's capacity is also where its id is, but that's sheer speculation fed by no concrete info in this post. – WhozCraig Oct 27 '19 at 07:58
  • 1
    Well what is in that heap? The server's IP address? It probably is, since you must use _something_ to talk to the server, which is either a name, an IP, or an IP/port combo, or anything the like. That _is_ a server identifier, literally. Just map IP to integer (literally _map_, using e.g. `std::map` or `std::unordered_map`, or just add the integer to the tuple stored in the heap, which saves one lookup) and there you have the integer that you want. Or just use the IP right away. If the load balancing works halfway properly, then that accounting is superfluous anyway (even distribution). – Damon Oct 27 '19 at 12:02

1 Answers1

0

It has been a while but, I simply created a struct with 2 integer variables. One of the variables is the value that I implement the binary heap according to. Other one is the number I wanted to track.

meliksahturker
  • 922
  • 2
  • 11
  • 20