in reply to data structure problem

you could build three hashes :) otherwise, i don't think you are going to get away from painful searching. or you could use a relational database, but that seems like a bit much...