Java tutorial
//package com.java2s; //License from project: LGPL import java.util.HashSet; import java.util.Hashtable; import java.util.Set; import java.util.Vector; public class Main { public static Hashtable<Integer, Set<Integer>> getNodeMembership(Hashtable<Integer, Set<Integer>> nIDComVH, final Vector<Set<Integer>> cmtyVV) { for (int i = 0; i < cmtyVV.size(); i++) { int CID = i; for (Integer NID : cmtyVV.get(i)) { if (nIDComVH.containsKey(NID)) { Set<Integer> x = nIDComVH.get(NID); x.add(CID); } else { Set<Integer> x = new HashSet<Integer>(); x.add(CID); nIDComVH.put(NID, x); } } } return nIDComVH; } public static Hashtable<Integer, Vector<Integer>> getNodeMembership(final Vector<Vector<Integer>> CmtyVV) { Hashtable<Integer, Vector<Integer>> NIDComVH = new Hashtable<Integer, Vector<Integer>>(); for (int CID = 0; CID < CmtyVV.size(); CID++) { for (Integer NID : CmtyVV.get(CID)) { if (!NIDComVH.contains(NID)) { Vector<Integer> v = new Vector<Integer>(); v.add(CID); NIDComVH.put(NID, v); } else { Vector<Integer> v = NIDComVH.get(NID); v.add(CID); NIDComVH.put(NID, v); } } } return NIDComVH; } }