private void CalcSimilarity(Account me, Account candidate, ref Span <uint> accounts) { Similarity similarity = Similarity.Of(me, candidate, accounts, out uint count); if (count == 0) { return; } if (limit <= _list.Count && similarity < _list[(uint)(_list.Count - 1)].Value) { return; } for (int i = 0; i < count; i++) { var item = new KeyValuePair <uint, Similarity>(accounts[i], similarity); if (_list.Count < (limit - 1)) { _list.Add(item); continue; } if (_list.Count == limit - 1) { _list.Add(item); _list.Sort(this); continue; } var index = _list.BinarySearch(item, this); if (index > 0) { continue; } var listIndex = (uint)(_list.Count - 1); var last = _list[listIndex]; if (Compare(last, item) > 0) { _list.RemoveAt((int)listIndex); var binarySearch = _list.BinarySearch(0, _list.Count, item, this); var insertAt = ~binarySearch; _list.Insert(insertAt, item); } } }
public bool AddAllLikes(string value) { if (string.IsNullOrWhiteSpace(value)) { return(false); } string[] values = value.Split(',', StringSplitOptions.RemoveEmptyEntries); likes = new HList <uint>(); foreach (var s in values) { if (!uint.TryParse(s, out var id)) { return(false); } likes.Add(id); } likes.SortDescending(); AddFilter(FilterTypes.likes_all); return(true); }
public bool AddInterestsAll(string value) { if (string.IsNullOrWhiteSpace(value)) { return(false); } string[] interests = value.Split(',', StringSplitOptions.RemoveEmptyEntries); var list = new HList <ushort>(); foreach (var interest in interests) { if (StringIndexer.Interests.TryGetIndex(interest, out ushort index)) { list.Add(index); } else { WillYieldZeroResults = true; return(true); } } //TODO: Remove ToArray() call and the list completely interestIndexes = new Interests(list); AddFilter(FilterTypes.interests_all); return(true); }
private static bool TryParseLikes(ref ParseContext pctx, out HList <NewLike> newLikes) { var arrayStartIndex = pctx.IndexOf((byte)'['); if (pctx[arrayStartIndex + 1] == ']') { newLikes = null; return(true); } pctx.Move(arrayStartIndex + 2); //skip start array + start object newLikes = UpdatePool.RentLikes(); NewLike like = default; while (pctx.Length > 0) { for (int i = 0; i < 3; i++) { if (pctx.StartsWith(likerBytes)) { pctx.Move(likerBytes.Length); if (!JsonParser.TryReadUInt(ref pctx, out like.Liker) || Database.NotExists(like.Liker)) { return(false); } } else if (pctx.StartsWith(likeeBytes)) { pctx.Move(likeeBytes.Length); if (!JsonParser.TryReadUInt(ref pctx, out like.Likee) || Database.NotExists(like.Likee)) { return(false); } } else if (pctx.StartsWith(tsBytes)) { pctx.Move(tsBytes.Length); if (!JsonParser.TryReadInt(ref pctx, out like.Ts)) { return(false); } } else { return(false); } } pctx.Move(2); // skip ",{" or "]}" in the end newLikes.Add(like); } return(true); }
public HList <Account> Execute(Account me) { if (me.likes == null || _cityIndex == 0 || _countryIndex == 0) { return(HList <Account> .Empty); } if (_cityIndex == ushort.MaxValue && _countryIndex == ushort.MaxValue && SuggestIndex.TryGetIndex(me.id, out HList <uint> indexed)) { var maxItems = Math.Min(limit, indexed.Count); for (uint i = 0; i < maxItems; i++) { _result.Add(Database.GetAccount(indexed[i])); } return(_result); } return(ExecuteWithoutIndex(me)); }
//metode til at lave nyt hus public async void AddNewHus() { try { Model.HusInfo temphusinfo = new Model.HusInfo(); temphusinfo.AntalBabyIHusstand = Newhus.AntalBabyIHusstand; temphusinfo.AntalBarnIHusstand = Newhus.AntalBarnIHusstand; temphusinfo.AntalTeenagerIHusstand = Newhus.AntalTeenagerIHusstand; temphusinfo.AntalVoksneIHusstand = Newhus.AntalVoksneIHusstand; temphusinfo.HusNummer = Newhus.HusNummer; temphusinfo.ComboBoxIndex2 = ComboBoxIndex; HList.Add(temphusinfo); GemData(); } catch (Exception x) { var dialog = new MessageDialog(x.Message); await dialog.ShowAsync(); } }
public bool AddInterestsAny(string value) { if (string.IsNullOrWhiteSpace(value)) { return(false); } string[] interests = value.Split(',', StringSplitOptions.RemoveEmptyEntries); var list = new HList <ushort>(); foreach (var interest in interests) { if (StringIndexer.Interests.TryGetIndex(interest, out ushort index)) { list.Add(index); } } interestIndexes = new Interests(list); WillYieldZeroResults = WillYieldZeroResults || interestIndexes.Count == 0; AddFilter(FilterTypes.interests_any); return(true); }
public HList <Account> ExecuteFilter() { IEnumerable <uint> indexToScan = GetAccounts(); Predicate predicate = FilterBuilder.GetFilter(_filters); _result.Clear(); foreach (var accountId in indexToScan) { var account = Database.GetAccount(accountId); if (account != null && predicate(account, this)) { _result.Add(account); if (_result.Count == limit) { break; } } } return(_result); }