markw
markw

Reputation: 630

A pair of tables?

I had this idea for working with two sets of data that are about equal in importance. In a project I'm working on, there are files with associated tags. Originally I just kept the data in a hash table with the files as keys and each file's tags as value. But there are often times when I want to look at all of the tags and say something about the files.

I decided I could keep track of two hash tables, a forward (file0->(tag1 tag2):file1->(tag2 tag3)) and a reverse (tag1->(file0):tag2->(file0 file1):tag3->(file1)). I haven't tried it yet, because I'm not sure if it's as useful as I think it might be or I'm just off my head. Is there any advantage to this? Prior usage?

Upvotes: 0

Views: 30

Answers (1)

Jim Garrison
Jim Garrison

Reputation: 86774

That will work if both keys and values are unique. If not, you will need a "MultiValueMap" that can handle multple entries per key.

Upvotes: 1

Related Questions