public void removeItemPref(long userID, long itemIDA, float prefValue) { PreferenceArray userPreferences = dataModel.getPreferencesFromUser(userID); try { buildAverageDiffsLock.EnterWriteLock(); FastByIDMap <RunningAverage> aMap = averageDiffs.get(itemIDA); int length = userPreferences.length(); for (int i = 0; i < length; i++) { long itemIDB = userPreferences.getItemID(i); float bValue = userPreferences.getValue(i); if (itemIDA < itemIDB) { if (aMap != null) { RunningAverage average = aMap.get(itemIDB); if (average != null) { if (average.getCount() <= 1) { aMap.remove(itemIDB); } else { average.removeDatum(bValue - prefValue); } } } } else if (itemIDA > itemIDB) { FastByIDMap <RunningAverage> bMap = averageDiffs.get(itemIDB); if (bMap != null) { RunningAverage average = bMap.get(itemIDA); if (average != null) { if (average.getCount() <= 1) { aMap.remove(itemIDA); } else { average.removeDatum(prefValue - bValue); } } } } } } finally { buildAverageDiffsLock.ExitWriteLock(); } }
private void pruneInconsequentialDiffs() { // Go back and prune inconsequential diffs. "Inconsequential" means, here, only represented by one // data point, so possibly unreliable var it1 = averageDiffs.entrySet().ToList(); for (int i = 0; i < it1.Count; i++) { FastByIDMap <RunningAverage> map = it1[i].Value; var it2 = map.entrySet().ToList(); for (int j = 0; j < it2.Count; j++) { RunningAverage average = it2[j].Value; if (average.getCount() <= 1) { map.remove(it2[j].Key); } } if (map.isEmpty()) { averageDiffs.remove(it1[i].Key); } else { map.rehash(); } } averageDiffs.rehash(); }
private static void removeTimestamp(long userID, long itemID, FastByIDMap <FastByIDMap <DateTime?> > timestamps) { FastByIDMap <DateTime?> map = timestamps.get(userID); if (map != null) { map.remove(itemID); } }
protected void processLine <T>(string line, FastByIDMap <T> data, FastByIDMap <FastByIDMap <DateTime?> > timestamps, bool fromPriorData) { bool flag2; int num5; PreferenceArray array2; int num6; float num7; if ((line.Length == 0) || (line[0] == COMMENT_CHAR)) { return; } string[] strArray = line.Split(new char[] { this.delimiter }); string str = strArray[0]; string str2 = strArray[1]; string str3 = strArray[2]; bool flag = strArray.Length > 3; string timestampString = flag ? strArray[3] : null; long key = this.readUserIDFromString(str); long itemID = this.readItemIDFromString(str2); if (this.transpose) { long num3 = key; key = itemID; itemID = num3; } T local = data.get(key); if (!fromPriorData) { IEnumerable <Preference> source = (IEnumerable <Preference>)local; if (flag || !string.IsNullOrWhiteSpace(str3)) { num7 = float.Parse(str3, CultureInfo.InvariantCulture); flag2 = false; if (this.uniqueUserItemCheck && (source != null)) { foreach (Preference preference in source) { if (preference.getItemID() == itemID) { flag2 = true; preference.setValue(num7); break; } } } if (!flag2) { if (source == null) { source = new List <Preference>(5); data.put(key, (T)source); } if (source is IList <Preference> ) { ((IList <Preference>)source).Add(new GenericPreference(key, itemID, num7)); } } this.addTimestamp(key, itemID, timestampString, timestamps); return; } if (source != null) { IEnumerator <Preference> enumerator = ((IEnumerable <Preference>)source.ToArray <Preference>()).GetEnumerator(); while (enumerator.MoveNext()) { Preference current = enumerator.Current; if (current.getItemID() == itemID) { if (source is IList <Preference> ) { ((IList <Preference>)local).Remove(current); } break; } } } removeTimestamp(key, itemID, timestamps); return; } PreferenceArray array = (PreferenceArray)local; if (flag || !string.IsNullOrWhiteSpace(str3)) { num7 = float.Parse(str3, CultureInfo.InvariantCulture); flag2 = false; if (this.uniqueUserItemCheck && (array != null)) { for (num5 = 0; num5 < array.length(); num5++) { if (array.getItemID(num5) == itemID) { flag2 = true; array.setValue(num5, num7); break; } } } } else { if (array != null) { flag2 = false; int num4 = array.length(); for (num5 = 0; num5 < num4; num5++) { if (array.getItemID(num5) == itemID) { flag2 = true; break; } } if (flag2) { if (num4 == 1) { data.remove(key); } else { array2 = new GenericUserPreferenceArray(num4 - 1); num5 = 0; for (num6 = 0; num5 < num4; num6++) { if (array.getItemID(num5) == itemID) { num6--; } else { array2.set(num6, array.get(num5)); } num5++; } data.put(key, (T)array2); } } } removeTimestamp(key, itemID, timestamps); goto Label_02F1; } if (!flag2) { if (array == null) { array = new GenericUserPreferenceArray(1); } else { array2 = new GenericUserPreferenceArray(array.length() + 1); num5 = 0; for (num6 = 1; num5 < array.length(); num6++) { array2.set(num6, array.get(num5)); num5++; } array = array2; } array.setUserID(0, key); array.setItemID(0, itemID); array.setValue(0, num7); data.put(key, (T)array); } Label_02F1: this.addTimestamp(key, itemID, timestampString, timestamps); }