本文整理汇总了C#中SortedSet.ToList方法的典型用法代码示例。如果您正苦于以下问题:C# SortedSet.ToList方法的具体用法?C# SortedSet.ToList怎么用?C# SortedSet.ToList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedSet
的用法示例。
在下文中一共展示了SortedSet.ToList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSpecialNumbers
//Its not clear where x is supposed to be defined, this function isn't specifically requested, don't like magic numbers
public static Tuple<double, double> GetSpecialNumbers(SortedSet<double> set, double x)
{
if (set.Count < 3)
throw new NotEnoughSetItemsException(
string.Format("GetSpecial numbers expects at least 3 items in the provided set, got {0}", set.Count));
Tuple<double, double> pair = new Tuple<double, double>(set.ToList()[2],set.GetViewBetween(set.Min, ApproximateNumberFunc(x)).Max);
return pair;
}
示例2: Main
static void Main(string[] args)
{
var sortedStudentSet = new SortedSet<Student>();
Random random = new Random();
for (int i = 0; i < 20; i++)
{
var student = new Student();
student.Name = "Name" + random.Next(100);
student.Id = random.Next(50000);
sortedStudentSet.Add(student);
}
sortedStudentSet.ToList().ForEach(Console.WriteLine);
}
示例3: ImportFromDataset
private static List<IArtist> ImportFromDataset(string filename, int column, int limit = int.MaxValue)
{
TextReader reader = new StreamReader(filename);
var artists = new SortedSet<IArtist>();
string line;
var sep = new[] {"\t"};
while ((line = reader.ReadLine()) != null && limit > 0)
{
var parts = line.Split(sep, StringSplitOptions.None);
artists.Add(new Artist(parts[column]));
limit--;
}
reader.Close();
return artists.ToList();
}
示例4: ParseTags
public static List<string> ParseTags(string tagsString)
{
if (string.IsNullOrWhiteSpace(tagsString))
{
return new List<string>();
}
string[] tags = tagsString.Split(tagSeparators);
var sortedTags = new SortedSet<string>();
foreach (string tag in tags)
{
string trimmedTag = tag.Trim();
if (!string.IsNullOrEmpty(trimmedTag))
{
sortedTags.Add(trimmedTag);
}
}
return sortedTags.ToList();
}
示例5: Main
static void Main(string[] args)
{
List<int> firstList = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).
Select(item => int.Parse(item)).ToList();
List<int> secondList = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).
Select(item => int.Parse(item)).ToList();
SortedSet<int> allItems = new SortedSet<int>();
for (int i = 0; i < firstList.Count; i++)
{
allItems.Add(firstList[i]);
}
foreach (var item in secondList)
{
allItems.Add(item);
}
allItems.ToList().ForEach(item => Console.Write(item + " "));
}
示例6: OnTick
public void OnTick(object source, ElapsedEventArgs e)
{
PortfolioManager pm = new PortfolioManager();
List<PositionMessage> pos = pm.GetOpenPositions();
List<string> owned = pos.Select(x => x.SymbolName).ToList<string>();
_owner.WatchForSell = owned;
SortedSet<string> watched = new SortedSet<string>();
IWatchListManager wlm = new WatchListManager();
List<WatchList> lists = wlm.GetAllWatchLists();
foreach (WatchList wl in lists)
{
foreach (WatchListItem i in wl.Items)
{
watched.Add(i.SymbolName);
}
}
_owner.WatchForBuy = watched.ToList<string>();
}
示例7: GetTags
public List<FrameType> GetTags()
{
var pattern = new StrWithCursor(Pattern);
var parsedTags = new SortedSet<FrameType>();
var tag = new StringBuilder();
while (pattern!='*')
{
if (pattern == '<')
{
DeterminateTag(pattern, tag);
parsedTags.Add(Frame.GetEnum(tag.ToString()));
tag.Clear();
}
else
pattern++;
}
return parsedTags.Count != 0 ? parsedTags.ToList() : null;
}
示例8: Prebuild
public override IEnumerable<FileModel> Prebuild(ImmutableList<FileModel> models, IHostService host)
{
host.LogInfo("Applying platform-version from metadata...");
models.RunAll(m =>
{
if (m.Type != DocumentType.Article)
{
return;
}
var page = m.Content as PageViewModel;
object value;
if (page?.Metadata != null &&
page.Metadata.TryGetValue("platform", out value))
{
page.Metadata.Remove("platform");
var list = GetPlatformVersionFromMetadata(value);
if (list != null)
{
list.Sort();
foreach (var item in page.Items)
{
if (item.Platform == null)
{
item.Platform = list;
}
else
{
var set = new SortedSet<string>(item.Platform);
foreach (var pv in list)
{
set.Add(pv);
}
item.Platform = set.ToList();
}
}
}
}
});
host.LogInfo("Platform applied.");
return models;
}
示例9: ImportFromDataset
public static List<IUser> ImportFromDataset(string filename, int limit = int.MaxValue)
{
TextReader reader = new StreamReader(filename);
var users = new SortedSet<IUser>();
string line;
var sep = new[] {"\t"};
while ((line = reader.ReadLine()) != null && limit > 0)
{
var parts = line.Split(sep, StringSplitOptions.None);
int age;
int.TryParse(parts[2], out age);
users.Add(new User(parts[0], DateTime.Parse(parts[4], CultureInfo.InvariantCulture), parts[1], age, parts[3]));
limit--;
}
reader.Close();
return users.ToList();
}
示例10: GetCoverage
public Coverage GetCoverage(SortedSet<MatchedPair> matches, double queryLength, FingerprintConfiguration configuration)
{
int minI = 0, maxI = 0, curMinI = 0, maxLength = 0;
var sortedMatches = matches.ToList();
for (int i = 1; i < sortedMatches.Count; ++i)
{
if (ConsecutiveMatchesAreLongerThanTheQuery(queryLength, sortedMatches, i, configuration))
{
// potentialy a new start of best matched sequence
curMinI = i;
}
if (i - curMinI > maxLength)
{
maxLength = i - curMinI;
maxI = i;
minI = curMinI;
}
}
double notCovered = 0d;
for (int i = minI + 1; i <= maxI; ++i)
{
if (sortedMatches[i].SubFingerprint.SequenceAt - sortedMatches[i - 1].SubFingerprint.SequenceAt > configuration.FingerprintLengthInSeconds)
{
notCovered += sortedMatches[i].SubFingerprint.SequenceAt - (sortedMatches[i - 1].SubFingerprint.SequenceAt + configuration.FingerprintLengthInSeconds);
}
}
double sourceMatchLength = SubFingerprintsToSeconds.AdjustLengthToSeconds(
sortedMatches[maxI].SubFingerprint.SequenceAt,
sortedMatches[minI].SubFingerprint.SequenceAt,
configuration) - notCovered;
double sourceMatchStartsAt = sortedMatches[minI].HashedFingerprint.StartsAt;
double originMatchStartsAt = sortedMatches[minI].SubFingerprint.SequenceAt;
return new Coverage(sourceMatchStartsAt, sourceMatchLength, originMatchStartsAt);
}
示例11: UpdateTaskListMetaData
public void UpdateTaskListMetaData()
{
var UniqueProjects = new SortedSet<string>();
var UniqueContexts = new SortedSet<string>();
var UniquePriorities = new SortedSet<string>();
foreach (Task t in Tasks)
{
foreach (string p in t.Projects)
{
UniqueProjects.Add(p);
}
foreach (string c in t.Contexts)
{
UniqueContexts.Add(c);
}
UniquePriorities.Add(t.Priority);
}
this.Projects = UniqueProjects.ToList<string>();
this.Contexts = UniqueContexts.ToList<string>();
this.Priorities = UniquePriorities.ToList<string>();
}
示例12: TestKeysAll
public void TestKeysAll()
{
Dictionary<string, int> testDict = new Dictionary<string, int>(TrueStringComparer.Comparer);
SortedSet<string> keys = new SortedSet<string>(TrueStringComparer.Comparer);
//var failingKeyC = new char[] { (char)33, (char)3, (char)1, (char)5, (char)3, (char)10, (char)1, (char)1, (char)0, (char)11, (char)3, (char)1, (char)15 };
//string failingKey = new String(failingKeyC);
//keys.Add(failingKey);
//testDict.Add(failingKey,123);
int count = 10000;
for (int i = 0; i < count; i++)
{
var key = NextKey(500);
keys.Add(key);
testDict.Add(key, i);
}
Assert.AreEqual(count, keys.Count);
Assert.AreEqual(count, testDict.Count);
CollectionAssert.AreEqual(keys.ToList(), testDict.Keys.OrderBy(item => item, TrueStringComparer.Comparer).ToList());
}
示例13: TestKeysRandom
public void TestKeysRandom()
{
Dictionary<string, int> testDict = new Dictionary<string, int>(TrueStringComparer.Comparer);
SortedSet<string> keys = new SortedSet<string>(TrueStringComparer.Comparer);
int count = 10000;
for (int i = 0; i < count; i++)
{
var key = RandomKey(500);
keys.Add(key);
testDict.Add(key, i);
}
Assert.AreEqual(count, keys.Count);
Assert.AreEqual(count, testDict.Count);
CollectionAssert.AreEqual(keys.ToList(), testDict.Keys.OrderBy(item => item, TrueStringComparer.Comparer).ToList());
}
示例14: doLoadSongList
private void doLoadSongList(GoogleMusicPlaylist playlist)
{
this.IsLoadingSongs = true;
if (playlist == null)
{
if (GooglePlayHandler.AllSongs == null)
{
if (GetAllSongs())
{
SortedSet<GoogleMusicSong> sortAll = new SortedSet<GoogleMusicSong>(GooglePlayHandler.AllSongs, new GoogleMusicSongComparer());
this.SongList = sortAll.ToList();
}
}
}
else
this.SongList = playlist.Songs;
this.IsLoadingSongs = false;
}
示例15: syncSqlCmds
/// <summary>
/// Converts translations to sql commands that'll insert and/or update translations to the database.
///
/// To determine whether an update or translation is needed, translations already in the database are queried and compared against
/// the translations passed into this method.
///
/// A two finger algorithm is used against the sorted database stream to the sorted translation parameter for a time
/// complexity of O(n+m). All statements are wrapped into a transaction.
/// </summary>
public string syncSqlCmds(SortedSet<Translation> translations)
{
var categoriesClause = categoriesSqlClause(translations.ToList()); //todo: change algorithm to work with HashSet.Enumerator
StringBuilder buff = new StringBuilder();
using (var conn = new MySqlConnection(FlashCardAppDB.instance.connectionString)){
var cmd = new MySqlCommand(
$"select italiano,category from translation where category in ({categoriesClause}) order by category,italiano", conn);
conn.Open();
MySqlDataReader rdr = cmd.ExecuteReader();
var translateEnumerator = translations.GetEnumerator();
var comparer = new TranslationComparer();
var hasNext = translateEnumerator.MoveNext();
Func <string,string> printNull = x => (x != null) ? $"'{x}'" : "null";
Translation dbt;
if (hasNext){
buff.AppendLine("start transaction;");
while (hasNext){ //read-only, forward-only stream
dbt = (rdr.Read()) ?
new Translation{ italiano = rdr.GetString("italiano"), category = rdr.GetString("category") } : null;
if (dbt == null || comparer.Compare(translateEnumerator.Current, dbt) < 0){ //Less than or remaining parsed translations
buff.AppendLine("insert into translation (italiano,category,espanol,priority) " +
$"values ('{translateEnumerator.Current.italiano}','{translateEnumerator.Current.category}',{printNull(translateEnumerator.Current.espanol)},{translateEnumerator.Current.priority});");
hasNext = translateEnumerator.MoveNext();
}else if (comparer.Compare(translateEnumerator.Current, dbt) == 0){ //Equal
buff.AppendLine($"update translation set espanol={printNull(translateEnumerator.Current.espanol)},priority={translateEnumerator.Current.priority} " +
$"where italiano='{translateEnumerator.Current.italiano}' and category='{translateEnumerator.Current.category}';");
hasNext = translateEnumerator.MoveNext();
} //Greater than... skip
}
buff.AppendLine("commit;");
}
return buff.ToString();
}
}