Enable matching to multiple hostgroups via hash-map

Credit to @lotherk for the original work, I just rebased it.