public void AddOrUpdate(int id, string name) { short nameId = _storage.Get(name); if (_names[id] == 0) { _ids.DelayAdd(id); } else { _byName[_names[id]].DelayRemove(id); } _names[id] = nameId; if (_byName[nameId] == null) { _byName[nameId] = DelaySortedList <int> .CreateDefault(); _byName[nameId].Load(id); } else { _byName[nameId].DelayAdd(id); } }
private void AddImpl(Like like, bool import) { if (_likee2likers[like.LikeeId] != null) { var list = _likee2likers[like.LikeeId]; { if (import) { var rawList = list.GetList(); int index = rawList.CustomBinarySearch(like.LikerId); if (index < 0) { list.Insert(~index, like.LikerId); } } else { if (!list.FullContains(like.LikerId)) { list.DelayAdd(like.LikerId); } } } } else { _likee2likers[like.LikeeId] = DelaySortedList <int> .CreateDefault(); _likee2likers[like.LikeeId].Load(like.LikerId); } DelaySortedList <LikeBucket> likes; if (_liker2likes[like.LikerId] == null) { _liker2likes[like.LikerId] = new DelaySortedList <LikeBucket>(BucketIdComparer.Default); } likes = _liker2likes[like.LikerId]; LikeBucket bucket = new LikeBucket(like.LikeeId, like.Timestamp.Seconds, 1); if (import) { var rawList = likes.GetList(); int index = rawList.BinarySearch(bucket, BucketIdComparer.Default); if (index >= 0) { rawList[index] += bucket; } else { likes.Insert(~index, bucket); } } else { likes.UpdateOrAdd(bucket, x => x + bucket); } }
public void AddOrUpdate(int id, UnixTime time) { var oldYear = _id2time[id].Year; _id2time[id] = time; if (_years.ContainsKey(oldYear)) { _years[oldYear].Remove(id); _byYear[oldYear].DelayRemove(id); } var newYear = time.Year; if (!_years.ContainsKey(newYear)) { _years[newYear] = new CountSet(); var list = _byYear[newYear] = DelaySortedList <int> .CreateDefault(); _years[newYear].Add(id); list.Load(id); } else { _years[newYear].Add(id); _byYear[newYear].DelayAdd(id); } }
public void AddOrUpdate(int id, string name) { short nameId = _storage.Get(name); if (_names[id] == 0) { _ids.DelayAdd(id); } else { _byName[_names[id]].DelayRemove(id); } _names[id] = nameId; DelaySortedList <int> nameGroup; if (!_byName.TryGetValue(nameId, out nameGroup)) { nameGroup = DelaySortedList <int> .CreateDefault(); _byName.Add(nameId, nameGroup); nameGroup.Load(id); } else { nameGroup.DelayAdd(id); } }
public SexContext() { _filter[0] = new CountSet(); _filter[1] = new CountSet(); _groups[0] = DelaySortedList <int> .CreateDefault(); _groups[1] = DelaySortedList <int> .CreateDefault(); }
public void Add(int id, short interestId) { _ids.Add(id); if (_id2AccId[interestId] == null) { _id2AccId[interestId] = DelaySortedList <int> .CreateDefault(); } _id2AccId[interestId].DelayAdd(id); }
public void LoadBatch(int id, short cityId) { _raw[id] = cityId; _ids.Load(id); if (_id2AccId[cityId] == null) { _id2AccId[cityId] = DelaySortedList <int> .CreateDefault(); } _id2AccId[cityId].Load(id); }
public void LoadBatch(int id, IEnumerable <short> interestsIds) { foreach (var interestId in interestsIds) { if (_id2AccId[interestId] == null) { _id2AccId[interestId] = DelaySortedList <int> .CreateDefault(); } _id2AccId[interestId].Load(id); } }
public void LoadBatch(int id, Phone phone) { _phones[id] = phone; if (!_code2ids.ContainsKey(phone.Code)) { _code2ids[phone.Code] = DelaySortedList <int> .CreateDefault(); } _code2ids[phone.Code].Load(id); _ids.Load(id); }
public void LoadBatch(int id, Email email) { email.Prefix = string.Intern(email.Prefix); _emails[id] = email; if (!_domain2ids.ContainsKey(email.DomainId)) { _domain2ids[email.DomainId] = DelaySortedList <int> .CreateDefault(); } _domain2ids[email.DomainId].Load(id); }
public StatusContext() { _raw[(int)Status.Complicated] = new CountSet(); _raw[(int)Status.Free] = new CountSet(); _raw[(int)Status.Reserved] = new CountSet(); _groups[(int)Status.Complicated] = DelaySortedList <int> .CreateDefault(); _groups[(int)Status.Free] = DelaySortedList <int> .CreateDefault(); _groups[(int)Status.Reserved] = DelaySortedList <int> .CreateDefault(); }
public void Add(int id, short countryId) { if (_raw[id] == 0) { _ids.DelayAdd(id); } _raw[id] = countryId; if (_id2AccId[countryId] == null) { _id2AccId[countryId] = DelaySortedList <int> .CreateDefault(); } _id2AccId[countryId].DelayAdd(id); }
public void LoadBatch(int id, UnixTime item) { var newYear = item.Year; if (!_years.ContainsKey(newYear)) { _years[newYear] = new CountSet(); _byYear[newYear] = DelaySortedList <int> .CreateDefault(); } _years[newYear].Add(id); _byYear[newYear].Load(id); _id2time[id] = item; }
public void LoadBatch(int id, string name) { short nameId = _storage.Get(name); _names[id] = nameId; if (_byName[nameId] == null) { _byName[nameId] = DelaySortedList <int> .CreateDefault(); } _byName[nameId].Load(id); _ids.Load(id); }
public void Add(int id, Phone phone) { if (!_phones[id].IsNotEmpty()) { _ids.DelayAdd(id); } _phones[id] = phone; if (!_code2ids.ContainsKey(phone.Code)) { _code2ids[phone.Code] = DelaySortedList <int> .CreateDefault(); } _code2ids[phone.Code].DelayAdd(id); }
public IIterator Filter( FilterRequest.EmailRequest email, DomainStorage domainStorage, IdStorage idStorage) { DelaySortedList <int> withDomain = null; if (email.Domain != null) { var domainId = domainStorage.Get(email.Domain); withDomain = _domain2ids.GetValueOrDefault(domainId); } IEnumerable <int> result = withDomain != null ? withDomain : idStorage.AsEnumerable(); if (email.Gt != null && email.Lt != null) { if (string.Compare(email.Gt, email.Lt) > 0) { return(ListHelper.EmptyInt); } return(result.Where(x => { string prefix = _emails[x].Prefix; return string.Compare(prefix, email.Gt) > 0 && string.Compare(prefix, email.Lt) < 0; }).GetIterator()); } if (email.Gt != null) { return(result .Where(x => string.Compare(_emails[x].Prefix, email.Gt) > 0) .GetIterator()); } else if (email.Lt != null) { return(result .Where(x => string.Compare(_emails[x].Prefix, email.Lt) < 0) .GetIterator()); } return(withDomain.GetIterator()); }
public void LoadBatch(int id, string lastname) { short nameId = _storage.Get(lastname); _names[id] = nameId; DelaySortedList <int> nameGroup; if (!_byName.TryGetValue(nameId, out nameGroup)) { nameGroup = DelaySortedList <int> .CreateDefault(); _byName.Add(nameId, nameGroup); } nameGroup.Load(id); _ids.Load(id); }
public static IIterator GetIterator(this DelaySortedList <int> list) { return(new SortedListIterator(list.GetList())); }
public void Suggest( int id, Dictionary <int, float> similarity, Dictionary <int, List <LikeBucket> > suggested, HashSet <int> selfIds, MainContext context, short cityId, short countryId) { bool curSex = context.Sex.Get(id); DelaySortedList <LikeBucket> buckets = _liker2likes[id]; if (buckets == null) { return; } foreach (var likeePair in buckets) { var likers = _likee2likers[likeePair.LikeeId]; if (likers == null) { continue; } foreach (var liker in likers) { if (curSex != context.Sex.Get(liker)) { continue; } if (cityId > 0 && cityId != context.Cities.Get(liker)) { continue; } if (countryId > 0 && countryId != context.Countries.Get(liker)) { continue; } float current = 0; if (!similarity.TryGetValue(liker, out current)) { current = 0; } float x = likeePair.Calc(); LikeBucket bucketY = new LikeBucket(likeePair.LikeeId, 0, 0); var likerList = _liker2likes[liker]; bucketY = likerList.Find(bucketY); float y = bucketY.Calc(); if (likeePair.TsSum * bucketY.Count == bucketY.TsSum * likeePair.Count) { current += 1.0f; } else { current += 1.0f / Math.Abs(x - y); } similarity[liker] = current; } } for (int i = 0; i < buckets.Count; i++) { selfIds.Add(buckets[i].LikeeId); } foreach (var liker in similarity.Keys) { suggested.Add(liker, _liker2likes[liker].GetList()); } }