本文整理汇总了C#中ConcurrentQueue.ToDictionary方法的典型用法代码示例。如果您正苦于以下问题:C# ConcurrentQueue.ToDictionary方法的具体用法?C# ConcurrentQueue.ToDictionary怎么用?C# ConcurrentQueue.ToDictionary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConcurrentQueue
的用法示例。
在下文中一共展示了ConcurrentQueue.ToDictionary方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReadAuthorFromFile
public static void ReadAuthorFromFile(string str)
{
IEnumerable<string> lines = File.ReadLines(Path.GetFullPath(str));
var line = lines.Where(x => (x != ""));
var results = new ConcurrentQueue<Author>();
Parallel.ForEach(line, l =>
{
Author author = Author.FromLine(l);
if (author != null)
{
results.Enqueue(author);
}
});
dicAllAuthors = results.ToDictionary(x => x.idAuthor, x => x);
}
示例2: ReadVenueFromFile
private static void ReadVenueFromFile(string str)
{
IEnumerable<string> lines = File.ReadLines(Path.GetFullPath(str));
var line = lines.Where(x => (x != ""));
var results = new ConcurrentQueue<Venue>();
Parallel.ForEach(line, l =>
{
Venue venue = Venue.FromLine(l);
if (venue != null)
{
results.Enqueue(venue);
}
});
Venue.dicAllVenues = results.ToDictionary(x => x.idVenue, x => x);
}
示例3: ReadPublicationFromFile
public static void ReadPublicationFromFile(string str)
{
IEnumerable<string> lines = File.ReadLines(Path.GetFullPath(str));
var line = lines.Where(x => (x != ""));
var results = new ConcurrentQueue<Publication>();
Parallel.ForEach(line, l =>
{
Publication publication = Publication.FromLine(l);
if (publication != null)
{
publication.curValue = 100;
results.Enqueue(publication);
}
});
Publication.dicAllPubs = results.ToDictionary(x => x.idPaper, x => x);
}
示例4: ReadKeywordFromFile
public static void ReadKeywordFromFile(string str)
{
IEnumerable<string> lines = File.ReadLines(Path.GetFullPath(str));
var line = lines.Where(x => (x != ""));
var results = new ConcurrentQueue<Keyword>();
Parallel.ForEach(line, l =>
{
Keyword keyword = Keyword.FromLine(l);
if (keyword != null)
{
results.Enqueue(keyword);
}
});
dicAllKeywords = results.ToDictionary(x => x.idKeyword, x => x);
}
示例5: ReadConferenceFromFile
//public static Dictionary<KeyValuePair<int, int>, double> dicSpaceStateValues = new Dictionary<KeyValuePair<int, int>, double>();
//public static Dictionary<KeyValuePair<int, int>, double> dicSpaceStateOldValues = new Dictionary<KeyValuePair<int, int>, double>();
//public static Dictionary<KeyValuePair<int, int>, Dictionary<int, double>> dicSpaceStateResults = new Dictionary<KeyValuePair<int, int>, Dictionary<int, double>>();
public static void ReadConferenceFromFile(string str)
{
IEnumerable<string> lines = File.ReadLines(Path.GetFullPath(str));
var line = lines.Where(x => (x != ""));
var results = new ConcurrentQueue<Conference>();
Parallel.ForEach(line, l =>
{
Conference conference = Conference.FromLine(l);
if (conference != null)
{
results.Enqueue(conference);
}
});
dicAllConferences = results.ToDictionary(x => x.idConference, x => x);
}
示例6: ReadPaperStemmingFromFile
public static void ReadPaperStemmingFromFile(string str)
{
IEnumerable<string> lines = File.ReadLines(Path.GetFullPath(str));
var line = lines.Where(x => (x != ""));
var results = new ConcurrentQueue<Paper>();
Parallel.ForEach(line, l =>
{
Paper paper = Paper.FromStemmingLine(l,'#');
if (paper != null)
{
results.Enqueue(paper);
}
});
dicAllPapers = results.ToDictionary(x => x.idPaper, x => x);
}
示例7: ReadKeywordPaperRelationFromFile
static void ReadKeywordPaperRelationFromFile(string str)
{
IEnumerable<string> lines = File.ReadLines(Path.GetFullPath(str));
var line = lines.Where(x => (x != ""));
var results = new ConcurrentQueue<KeyValuePair<int,int>>();
Parallel.ForEach(line, l =>
{
string[] datas = l.Split(',','\t');
try
{
int idPaper = Convert.ToInt32(datas[0].Trim('"'));
int idKeyword = Convert.ToInt32(datas[1].Trim('"'));
if (dicAllPapers.Keys.Contains(idPaper) && dicAllKeywords.Keys.Contains(idKeyword))
{
lock (lock_paper)
{
dicAllPapers[idPaper].dicKeywords.Add(idKeyword, dicAllKeywords[idKeyword]);
}
lock (lock_keyword)
{
dicAllKeywords[idKeyword].dicPapers.Add(idPaper, dicAllPapers[idPaper]);
}
lock (lock_state)
{
State state = new State(idKeyword, idPaper, 100);
dicAllStates.Add(new KeyValuePair<int, int>(idKeyword,idPaper),state);
dicAllPapers[idPaper].dicState.Add(idKeyword, state);
dicAllKeywords[idKeyword].dicState.Add(idPaper, state);
}
results.Enqueue(new KeyValuePair<int, int>(idKeyword, idPaper));
}
}
catch (Exception ex)
{
Console.WriteLine("Error {0} at line:{1}", ex.Message, l);
}
});
//dicAllStates = results.ToDictionary(x => x, x => new State(x.Key, x.Value, 100.0));
dicSpaceStateValues = results.ToDictionary(x => x, x=> 0.0);
dicSpaceStateOldValues = results.ToDictionary(x => x, x => 0.0);
dicSpaceStateResults = results.ToDictionary(x => x, x=> new Dictionary<int,double>());
}
示例8: ReadFromFileResult
static void ReadFromFileResult(int step)
{
IEnumerable<string> lines = File.ReadLines(Path.GetFullPath(directory+
"\\result-round-" + step.ToString() + ".csv"));
var line = lines.Where(x => (x != ""));
var results = new ConcurrentQueue<KeyValuePair<KeyValuePair<int, int>,double>>();
Parallel.ForEach(line, l =>
{
string[] datas = l.Split(',');
try
{
int idKeyword = Convert.ToInt32(datas[0].Trim('"'));
int idPaper = Convert.ToInt32(datas[1].Trim('"'));
int idValue = Convert.ToInt32(datas[2].Trim('"'));
results.Enqueue(new KeyValuePair<KeyValuePair<int, int>,double>(
new KeyValuePair<int,int>(idKeyword, idPaper),idValue));
}
catch (Exception ex)
{
Console.WriteLine("Error {0} at line:{1}", ex.Message, l);
}
});
dicSpaceStateValues.Clear();
dicSpaceStateValues = results.ToDictionary(x => x.Key, x => x.Value);
}
示例9: MoveToNextState
static void MoveToNextState(int step, bool readvaluefromfile)
{
object lock_loop=new object();
double max_loop=0;
var results = new ConcurrentQueue<KeyValuePair<KeyValuePair<int,int>,double>>();
Parallel.ForEach(dicSpaceStateValues.Keys, key =>
{
var statevalue = dicSpaceStateResults[key];
lock (lock_loop)
{
if (step > 0)
{
max_loop = max_loop < (statevalue[step] - statevalue[step - 1]) ? (statevalue[step] - statevalue[step - 1]) : max_loop;
}
else
{
max_loop = 10000;
}
}
results.Enqueue(new KeyValuePair<KeyValuePair<int, int>, double>(key, statevalue[step]));
});
if (max_loop < 10) return; //stop
dicSpaceStateValues.Clear();
dicSpaceStateValues = results.ToDictionary(x => x.Key, x => x.Value);
if (readvaluefromfile)
{
ReadFromFileResult(step);
}
List<KeyValuePair<KeyValuePair< int, int>,double>> myList = dicSpaceStateValues.ToList();
myList.Sort(
delegate(KeyValuePair<KeyValuePair<int, int>, double> firstPair,
KeyValuePair<KeyValuePair<int, int>, double> nextPair)
{
return nextPair.Value.CompareTo(firstPair.Value);
});
Dictionary<double, KeyValuePair<int, int>> choiceDict = new Dictionary<double, KeyValuePair<int,int>>();
choiceDict.Add(myList[0].Value,myList[0].Key);
double aggregateValue = myList[0].Value;
double sumValue = myList.Sum(x => x.Value);
myList.Where(x => x.Value == 0).ToList();
for (int i = 1; i < myList.Count; i++)
{
choiceDict.Add(aggregateValue += myList[i].Value, new KeyValuePair<int, int>(
myList[i].Key.Key,myList[i].Key.Value));
}
//Get current value of all state, for first time this equal 1
//Todo: set the value of diceChooseNextPaper
int diceChooseFirstState = random.Next(1, (int)aggregateValue);
List<double> choiceKeys = choiceDict.Keys.ToList();
int index=0;
for (index=0; index<choiceKeys.Count;index++){
if (diceChooseFirstState > choiceKeys[index])
{
diceChooseFirstState = (int)choiceKeys[index];
break;
}
}
if (index == choiceKeys.Count)
{
diceChooseFirstState = (int)choiceKeys[0];
}
KeyValuePair<int, int> chooseState = choiceDict[diceChooseFirstState];
//diceChooseState to begin a next move
//int diceChooseState = random.Next(dicSpaceStateValues.Count);
//KeyValuePair<int, int> chooseState = dicSpaceStateValues.Keys.ToList()[diceChooseState];
List<KeyValuePair<int, int>> listStates = dicSpaceStateValues.Keys.ToList();
int loop = dicSpaceStateValues.Count * 50000;
//then reset all states to next move
double oldval = dicSpaceStateValues.Sum(x => x.Value);
ResetAllStates();
Stopwatch sw = new Stopwatch();
sw.Start();
double s =Math.Pow( loop,1.0/3);
for (int k = 0; k < s+1; k++)
{
Parallel.For(0, (int)s+1, j =>
{
Parallel.For(0, (int)s + 1, i =>
{
ProcessMoveNextState(chooseState, listStates);
});
});
//sw.Stop();
//Console.WriteLine("loop {0}:-{1}, time:{2}",k, dicSpaceStateValues.Sum(x => x.Value),sw.Elapsed);
//sw.Restart();
}
sw.Stop();
Console.WriteLine("loop {0}, time:{1}", dicSpaceStateValues.Sum(x => x.Value), sw.Elapsed);
Parallel.ForEach(dicSpaceStateValues, dp => {
dicSpaceStateResults[dp.Key][step + 1] = dp.Value;
});
WriteResultToFile( step,"-");
}