Efficient data structure for a record consisting of a tuple and its value

I want to store sort of a tuple and a value as an entry. I mean something like this

A B -> 1
A C -> 2
E F -> 3
C D -> 4

The first two values are always unique, in the sense A and B occur only once together. What would be an efficient data structure for the purpose, keeping in mind that I may need to fetch any of the three fields from an entry efficiently ?

If possible, please provide some relevant code !!


A Map would work well. You need to have an object to represent the first two items. Make sure that the hashCode and equals methods are implemented correctly on your new class. Then you can use that class for the key.

Map<MyKeyClass, Integer> map = new HashMap<MyKeyClass, Integer>();
map.put(new MyKeyClass("A", "B"), 1);
map.put(new MyKeyClass("A", "C"), 2);

Need Your Help

How to pass the correct data format from SQL to PHP

php javascript ajax json highcharts

I need to create a basic column chart using highcharts. Here's my PHP code:

Image dragging on a UIScrollView

iphone ios objective-c uiscrollview mwphotobrowser

A UIViewController is called when a user touches an image on a UITableViewCell.

how to make a transparent form when a VCL Style is enabled?

delphi delphi-xe2 vcl-styles

I'm using the following code to make a form transparent, but when the application has a VCL style enabled the form is paint with the background color of the VCL style instead of be transparent.