Since UnitGetTag returns an int (presumably from an enumerated list of tags defined for the map in the editor), uniqueness of its value cannot be guaranteed; it's rather more like a Preset CustomValue for pre-placed objects.
According to the GUI documentation, the int is unique. It also works for non pre-placed units.
Quote:
A unit's tag is a unique integer associated with that unit. The tag will never change and will never be associated with a different unit.
The best way to achieve this is: Each time you retrieve the unit tag, you store it into the global datatable as key, and the unit as value.
Then you can create a reverse function using datatable lookup with O(1) complexity. :)
Make sure to remove dying or removed units from the datatable again though, otherwise it will get bigger and bigger over time.
Well that escalated quickly.
I feel honored!
According to the GUI documentation, the int is unique. It also works for non pre-placed units.
Good question. There is no native way.
The best way to achieve this is: Each time you retrieve the unit tag, you store it into the global datatable as key, and the unit as value.
Then you can create a reverse function using datatable lookup with O(1) complexity. :)
Make sure to remove dying or removed units from the datatable again though, otherwise it will get bigger and bigger over time.