private ElemIdSimilarityPair[] getKwindow(HashMap<Integer, DataRow> train,
			DataRow query, SimilarityCalculator simCal, boolean considerTime,
			int columnId, long timeWindow) {
		ElemIdSimilarityPair[] kwindow;
		if (cache.containsKey(query.getId())) {
			kwindow = cache.get(query.getId());
		} else {
			kwindow = new ElemIdSimilarityPair[k];
			int elemCnt = 0;
			double sim;
			for (Entry<Integer, DataRow> entry : train.entrySet()) {
				if (entry.getKey() == query.getId()) {
					// exclude the row itself
					continue;
				}
				if (considerTime == true) {
					sim = simCal.getSimilarity(entry.getValue(), query,
							columnId, timeWindow);
				} else {
					sim = simCal.getSimilarity(entry.getValue(), query);
				}

				// put <userId, similarity> into kwindow
				if (elemCnt < k) { // there's still space
					kwindow[elemCnt] = new ElemIdSimilarityPair(entry.getKey(),
							sim);
					elemCnt++;
					if (elemCnt == k) {
						Arrays.sort(kwindow);
					}
				} else {
					if (sim <= kwindow[0].getSimilarity()) {
						continue;
					}
					kwindow[0] = new ElemIdSimilarityPair(entry.getKey(), sim);
					Arrays.sort(kwindow);
				}
			}
			cache.put(query.getId(), kwindow);
		}
		return kwindow;
	}