java - Fastest way to restructure a HashMap -


I have a hushmap that maps to an ArrayList of the products that sell companies, such as: < Pre> this company - & gt; [Product A, Productby ...] that company - & gt; [Product C, Product A ...]

Therefore it is very easy to create a list of products given to a particular company, note that many companies can sell the same product. The issue is that I should also be given a specific product, which sell it to all companies. And this type of lookup can be done once or at a time, I am thinking the most effective way of providing this functionality.

Currently, I am creating a new data structure by mapping it again and its producer with my vendor through each of the analytics. Although it is expensive, because I have to check to see if I am making a Hashmap in it, before adding that product every time it is included in the key as well, it is also that I get the list every time To add new vendor, remove old allylists. For each entry I can not just see a quick way to do this, however, maybe someone has some insights The process can provide?

How about changing a HashSet to ArrayList?

  list & lt; String & gt; FindCompanies (map & lt; string; set & lt; string & gt; & gt; company form, string product) {list & lt; String & gt; Companies = new arreelist & lt; String & gt; (); (Map entry.lt; string; set & lt; string & gt; & gt; entry: companyToProducts) {set & lt; String & gt; Products = entry.jet (); If (products.contains (Products)) {companies.add (entry.getKey ()); }} Return companies; }   

Another common method is to use a column for the product with a column for a database and a column for the company, and then it must:

  select CompanyToProduct from a specific company where the product = 'paneer';    

Comments