public IEnumerable <ListBoxItem> GetList() { List <ListBoxItem> list = new List <ListBoxItem>(); for (int i = 0; i < datas.Count; ++i) { ListBoxItem item = new ListBoxItem(); item.Content = datas[i].toString(); if (datas[i].mode) { Avalonia.Media.SolidColorBrush brush = new Avalonia.Media.SolidColorBrush(); brush.Color = Colors.DarkRed; item.Background = brush.ToImmutable(); } else if (datas[i].contrib.Contains(id)) { Avalonia.Media.SolidColorBrush brush = new Avalonia.Media.SolidColorBrush(); brush.Color = Colors.DarkViolet; item.Background = brush.ToImmutable(); } item.DataContext = datas[i]; list.Add(item); } return(list.ToImmutableArray()); }
public IEnumerable <ListBoxItem> Search(string s) { List <Tuple <byte, int> > tuples = new List <Tuple <byte, int> >(); int Hash1, Hash2; try { Hash1 = new MolCalculator(s, AtomDB.hash1, 998244353).Calculate(); Hash2 = new MolCalculator(s, AtomDB.hash2, 1234567891).Calculate(); } catch (Exception) { Hash1 = Hash2 = -1; } for (int i = 0; i < datas.Count; ++i) { byte mode = datas[i].Filte(s, Hash1, Hash2); if (mode == 0) { continue; } tuples.Add(new Tuple <byte, int>(mode, i)); } tuples.Sort(); List <ListBoxItem> list = new List <ListBoxItem>(); for (int j = 0; j < tuples.Count; ++j) { int i = tuples[j].Item2; ListBoxItem item = new ListBoxItem(); item.Content = datas[i].toString(); if (datas[i].mode) { Avalonia.Media.SolidColorBrush brush = new Avalonia.Media.SolidColorBrush(); brush.Color = Colors.DarkRed; item.Background = brush.ToImmutable(); } else if (datas[i].contrib.Contains(id)) { Avalonia.Media.SolidColorBrush brush = new Avalonia.Media.SolidColorBrush(); brush.Color = Colors.DarkViolet; item.Background = brush.ToImmutable(); } item.DataContext = datas[i]; list.Add(item); } return(list.ToImmutableArray()); }