private void Add(KeySet <string> keySet) { CleanOld(); SubsetInfo element = null; if (!_keySetSubset.TryGetValue(keySet, out element)) { element = new SubsetInfo() { Timestamp = DateTime.UtcNow, KeySet = keySet }; _keySetSubset.Add(keySet, element); } else { var prevTimestamp = element.Timestamp; element.Timestamp = DateTime.UtcNow; _datetimeSubset.Remove(prevTimestamp); } _datetimeSubset.Add(element.Timestamp, element); ElementUpdateCounter(element, 1); }
public void AddNew(KeySet <T> keySet, ISet <U> documents) { if (_keySetToDocuments.ContainsKey(keySet.GetHashCode())) { throw new Exception("Item already exists in dictionary"); } _keySetToDocuments.Add(keySet.GetHashCode(), documents); }
private void SubsetGeneratorDeep( string[] keys, int level, int position, KeySet <string> inputKeySet, Guid documentId) { if (position >= keys.Length || level >= keys.Length) { return; } KeySet <string> newss = new KeySet <string>(inputKeySet); string key = keys[position]; newss.Add(key); bool keySetEncountered = false; if (_keySetExpenses.ContainsKey(newss)) { keySetEncountered = true; } else if (inputKeySet.Count > 0) { KeySet <string> ks = new KeySet <string>(key); ISet <Guid> ksExpenses = null; _keySetExpenses.TryGetValue(ks, out ksExpenses); ISet <Guid> ssExpenses = null; _keySetExpenses.TryGetValue(inputKeySet, out ssExpenses); if (ksExpenses != null && ssExpenses != null) { var expsIds = ksExpenses.Intersect(ssExpenses); var expenseDictionarySet = new HashSet <Guid>(expsIds); if (!documentId.Equals(new Guid())) { expenseDictionarySet.Add(documentId); } keySetEncountered = true; _keySetExpenses.AddNew(newss, expenseDictionarySet); } } if (keySetEncountered) { SubsetGeneratorDeep(keys, level + 1, position + 1, new KeySet <string>(newss), documentId); if (!documentId.Equals(new Guid())) { _keySetExpenses.Add(newss, documentId); } } SubsetGeneratorDeep(keys, level, position + 1, inputKeySet, documentId); }
public void Add(KeySet <T> keySet, U document) { ISet <U> documents; if (_keySetToDocuments.TryGetValue(keySet.GetHashCode(), out documents)) { documents.Add(document); } else { documents = new HashSet <U>(); documents.Add(document); _keySetToDocuments.Add(keySet.GetHashCode(), documents); } }
public int GetHashCode(KeySet <T> set) { var list = set.Keys.ToList(); list.Sort(); int hashCode = 13; list.ForEach(s => { unchecked { hashCode = (hashCode * 397) ^ s.GetHashCode(); } }); return(hashCode); }
private IEnumerable <Guid> SearchIndexIntersect(KeySet <string> correctedKeys) { Document doc = new Document { Guid = new Guid(), Body = string.Join(" ", correctedKeys) }; IEnumerable <Guid> resultGuids = ProcessDocumentForSearch(doc) .Select(e => new KeySet <string>(e)) .Select(k => { ISet <Guid> guids = new HashSet <Guid>(); _keySetExpenses.TryGetValue(k, out guids); return(guids); }) .Intersect(); return(resultGuids); }
public (IEnumerable <SuggestedWord>, IEnumerable <Guid>) Search(string keys) { var suggestions = keys.Split(' ') .AsEnumerable() .Select(_wordSuggester.GetWordOrSuggestion); if (suggestions.Any(s => s.NotFound)) { return(suggestions, new List <Guid>()); } KeySet <string> keySet = new KeySet <string>(suggestions.Select(sw => sw.Word)); ISet <Guid> guids = new HashSet <Guid>(); if (_keySetExpenses.TryGetValue(keySet, out guids)) { return(suggestions, guids); } else { return(suggestions, SearchIndexIntersect(keySet)); } }
public bool ContainsKey(KeySet <T> ks) { return(_keySetToDocuments.ContainsKey(ks.GetHashCode())); }
public bool TryGetValue(KeySet <T> keySet, out ISet <U> documents) { return(_keySetToDocuments.TryGetValue(keySet.GetHashCode(), out documents)); }
public ISet <U> this[KeySet <T> index] { get { return(_keySetToDocuments[index.GetHashCode()]); } }
public void AddNew(KeySet <T> keySet, IEnumerable <U> documents) { AddNew(keySet, new HashSet <U>(documents)); }
public void Add(T key, U document) { var keySet = new KeySet <T>(key); Add(keySet, document); }
public bool Equals(KeySet <T> x, KeySet <T> y) { return(x.Keys.SetEquals(y.Keys)); }