java - Map reducing algorithm -


how can reduce map<integer, list<integer>>?

let reduce'd map map each integer value of list<integer> unique , not duplicated.

example:

map a:

 0 --> (0)  1 --> (1, 2)   2 --> (2, 1) 

would reduce to:

 0 --> (0)  1 --> (1, 2) 

or

 0 --> (0)  2 --> (2, 1) 

notice either deletion of key 1 or 2 acceptable since produces reduced map.

edit: when element maps itself, should remain separate, such 0 --> 0. however, when multiple values have integer's in common, should merged.

try this

class reducedmap extends hashmap<integer, list<integer>> {     private set<set<integer>> set = new hashset<set<integer>>();      @override     public list<integer> put(integer key, list<integer> value) {         set<integer> set = new hashset<integer>(value);         if (!this.set.add(set)) {             return new arraylist<integer>(set);         }         return super.put(key, value);     }       ... 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -