JAVA: How to join a HashTable with itself? -
what elegant way join 2 hashtables?
i have hashtable , cannot use array or list or set instead, because messes dealing custom-class. @ least that's think.
**hashtable<itemset, integer> frequentitemsetl1 = new hashtable<>();** (map.entry<itemset, integer> entry : candidateitemsetc1.entryset()) { if (entry.getvalue() >= supportthreshold) { frequentitemsetl1.put(entry.getkey(), entry.getvalue()); }
which contains: key-value-pairs.
- key = number of itemset
- value = number of occurrences of itemset in data
looks this:
{1}, 3 {2}, 23 {3}, 7 {4}, 18 .....
i need keys of frequentitemsetl1 join themselves;
result should be:
{1, 2} {1, 3} {1, 4} {2, 3} {2, 4} {3, 4}
i experimented 2 for-loops , keysets did not far. need fresh ideas.
tried this:
for (int = 0; < frequentitemsetl1.size(); i++) { integer item1 = frequentitemsetl1.get(i); (int j = + 1; j < frequentitemsetl1.size(); j++) { integer item2 = frequentitemsetl1.get(j); // create new candidate combining itemset1 , itemset2 candidateitemsetc2.put(item1, item2); }
since nobody able help, clarify , others, looking this:
list<itemset> candidateitemsetc2 = new arraylist<>(); hashtable<itemset, integer> frequentitemsetl2 = new hashtable<>(); // each itemset i1 , i2 of level k-1 (itemset : frequentitemsetl1.keyset()) { (itemset is2 : frequentitemsetl1.keyset()) { if (is.equals(is2)) { continue; } if (is.set.length != is2.set.length) { continue; } boolean shouldjoin = true; (int = 0; < is.set.length - 1; i++) { if (is.set[i] != is2.set[i]) { shouldjoin = false; } } if (shouldjoin == false) { continue; } int[] join = new int[is.set.length + 1]; (int = 0; < is.set.length; i++) { join[i] = is.set[i]; } join[join.length - 1] = is2.set[is2.set.length - 1]; arrays.sort(join); itemset joinedset = new itemset(join); if (!candidateitemsetc2.contains(joinedset)) { candidateitemsetc2.add(joinedset); } (int p = 0; p < candidateitemsetc2.size(); p++) { //system.out.print(candidateitemsetc2.get(p)); } }
Comments
Post a Comment