techny.color 0 Newbie Poster

guys please tell me why my code for searching in hash for song database after i FFT n calculate hashed point (4 point) keep failing... please help me.. i don't know where i get it wrong
this is the code

private static void search(Hashtable<Long, ArrayList<Integer>> sHash) {

		NumberFormat formatter = NumberFormat.getInstance();

		System.out.println("\tBegin searching process...");

		Hashtable<Long, ArrayList<DataPoint>> resultHash = new Hashtable<Long, ArrayList<DataPoint>>(10);

		for (Long hash : sHash.keySet()) {

			ArrayList<Integer> sTimes = sHash.get(hash);

			ArrayList<SongTime> mHash = DBUtil.searchHash(hash);

			for (SongTime st : mHash) {

				ArrayList<DataPoint> al = resultHash.get(st.songId);

				if (null == al)

					al = new ArrayList<DataPoint>();

				for (Integer time : sTimes) {

					DataPoint dp = new DataPoint();

					dp.hash = hash;

					dp.songTimeId = st.timeId;

					dp.timeId = time;

					al.add(dp);

				}

				resultHash.put(st.songId, al);

			}

		}



		System.out.println("\tBegin matching process...");

		// double topP = 0;

		int top = 0;

		int d = 0;

		long id = 0;

		for (Long songId : resultHash.keySet()) {

			String songName = DBUtil.getSongName(songId);

			ArrayList<DataPoint> al = resultHash.get(songId);

			Hashtable<Integer, Integer> ht = new Hashtable<Integer, Integer>();

			for (DataPoint dp : al) {

				// System.out.println("\t\t" + dp.diff());

				int diff = dp.diff();

				if (diff >= 0) {

					Integer count = ht.get(diff);

					if (null == count)

						count = 0;

					ht.put(diff, new Integer(count + 1));

				}

			}



			int sCount = 0;

			for (Integer diff : ht.keySet()) {

				int count = ht.get(diff);

				// double per = (double)count / (double)al.size() * 100.0;

				if (count > 1) {

					if ( count > top ) {

						// if ( per > topP ) {

						top = count;

						id = songId;

						d = diff;

					}

					if ( count > sCount ) {

						sCount = count;

						d = diff;

					}

					// System.out.println("\t\t\t" + diff + "\t-> " + count);

				}

			}

			double percentage = ( (double)sCount / (double)sHash.size() * 100.0 ); 

			System.out.println("\t\t" + formatter.format(percentage) + " %\t-> " + 

					sCount + " / " + al.size() + " / " + sHash.size() + " -> " + d + " ( " + songName + " )");

			// System.out.println("\t\t\tHighest Match Count : " + top);

		}

		System.out.println("\tFinal : " + DBUtil.getSongName(id));

		System.out.println();

	}



}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.