Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Save the whales
Aug 31, 2004

by T. Finn
I'll state my question using Java terminology, but I'm curious as to whether there's a general name for this kind of data structure.

Recently I came upon the need for a data structure that is a bit of a cross between a Map and a Set. I ended up calling it BinaryRelation<L, R>. Its most important methods are:

code:
/*
pairs the given left-hand and right-hand values
*/
void put(L left, R right);

/*
returns a collection view of the left-hand values paired with the specified right-hand value
*/
Collection<L> getLeft(R right);

/*
returns a collection view of the right-hand values paired with the specified left-hand value
*/
Collection<R> getRight(L left);
It's kind of like a bidirectional map in that you can find associated values for keys or associated keys for values, but it's different in that neither keys nor values must be unique - only key-value pairs must be unique.

I've already written the Java code to implement this, so I'm not asking how it can be done, but I'm curious - is there a general name for this kind of data structure? Has it been implemented in any popular programming languages or libraries? I wasn't able to find anything like this after a bit of Googling and I was surprised because it seems like such a useful way of describing a relation between two sets of objects. I know for certain I'm going to use it in every web application I make from here on out.

Adbot
ADBOT LOVES YOU

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply