protected void processLineWithoutID(String line, FastByIDMap <FastIDSet> data, FastByIDMap <FastByIDMap <DateTime?> > timestamps) { if (String.IsNullOrWhiteSpace(line) || line[0] == COMMENT_CHAR) { return; } var tokens = SplitLine(line); string userIDString = tokens[0]; string itemIDString = tokens[1]; bool hasPreference = tokens.Length > 2; string preferenceValueString = hasPreference ? tokens[2] : ""; bool hasTimestamp = tokens.Length > 3; string timestampString = hasTimestamp ? tokens[3] : null; long userID = readUserIDFromString(userIDString); long itemID = readItemIDFromString(itemIDString); if (transpose) { long tmp = userID; userID = itemID; itemID = tmp; } if (hasPreference && !hasTimestamp && String.IsNullOrEmpty(preferenceValueString)) { // Then line is of form "userID,itemID,", meaning remove FastIDSet itemIDs = data.Get(userID); if (itemIDs != null) { itemIDs.Remove(itemID); } removeTimestamp(userID, itemID, timestamps); } else { FastIDSet itemIDs = data.Get(userID); if (itemIDs == null) { itemIDs = new FastIDSet(2); data.Put(userID, itemIDs); } itemIDs.Add(itemID); addTimestamp(userID, itemID, timestampString, timestamps); } }
/// This exists because FastIDSet has 'retainAll' as MASK, but there is /// no count of the number of items in the set. size() is supposed to do /// this but does not work. private static int mask(FastIDSet commonSet, FastIDSet otherSet, long maxItemID) { int count = 0; for (int i = 0; i <= maxItemID; i++) { if (commonSet.Contains(i)) { if (otherSet.Contains(i)) { count++; } else { commonSet.Remove(i); } } } return(count); }
public List <IRecommendedItem> RecommendedBecause(long userID, long itemID, int howMany) { //Preconditions.checkArgument(howMany >= 1, "howMany must be at least 1"); IDataModel model = GetDataModel(); TopItems.IEstimator <long> estimator = new RecommendedBecauseEstimator(this, userID, itemID); IPreferenceArray prefs = model.GetPreferencesFromUser(userID); int size = prefs.Length(); FastIDSet allUserItems = new FastIDSet(size); for (int i = 0; i < size; i++) { allUserItems.Add(prefs.GetItemID(i)); } allUserItems.Remove(itemID); return(TopItems.GetTopItems(howMany, allUserItems.GetEnumerator(), null, estimator)); }
public void testVersusHashSet() { FastIDSet actual = new FastIDSet(1); var expected = new HashSet<int>(); //1000000 var r = RandomUtils.getRandom(); for (int i = 0; i < 1000000; i++) { double d = r.nextDouble(); var key = r.nextInt(100); if (d < 0.4) { Assert.AreEqual(expected.Contains(key), actual.Contains(key)); } else { if (d < 0.7) { Assert.AreEqual(expected.Add(key), actual.Add(key)); } else { Assert.AreEqual(expected.Remove(key), actual.Remove(key)); } Assert.AreEqual(expected.Count, actual.Count() ); Assert.AreEqual(expected.Count==0, actual.IsEmpty()); } } }
public void testSizeEmpty() { FastIDSet set = new FastIDSet(); Assert.AreEqual(0, set.Count()); Assert.True(set.IsEmpty()); set.Add(1); Assert.AreEqual(1, set.Count()); Assert.False(set.IsEmpty()); set.Remove(1); Assert.AreEqual(0, set.Count()); Assert.True(set.IsEmpty()); }
/// This exists because FastIDSet has 'retainAll' as MASK, but there is /// no count of the number of items in the set. size() is supposed to do /// this but does not work. private static int mask(FastIDSet commonSet, FastIDSet otherSet, long maxItemID) { int count = 0; for (int i = 0; i <= maxItemID; i++) { if (commonSet.Contains(i)) { if (otherSet.Contains(i)) { count++; } else { commonSet.Remove(i); } } } return count; }