本文整理汇总了C#中System.Collections.Dictionary.OrderByDescending方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.OrderByDescending方法的具体用法?C# Dictionary.OrderByDescending怎么用?C# Dictionary.OrderByDescending使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Dictionary
的用法示例。
在下文中一共展示了Dictionary.OrderByDescending方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CriarIndice
private void CriarIndice()
{
List<INDICE> indices = new List<INDICE>();
Dictionary<VOCABULARIO,int> dicIndice = new Dictionary<VOCABULARIO,int>();
foreach (var termo in Termos)
{
VOCABULARIO voc = new VOCABULARIO();
//vai criar um termo na base caso não exista e retornar com seu ID
voc = _vocabularioRepositorio.GetVocabularioByTermo(termo);
if (dicIndice.ContainsKey(voc))
{
//existe então adiciona mais um na frequencia do termo no documento
dicIndice[voc]++;
}
else
{
//caso contrario será um
dicIndice[voc] = 1;
}
}
//implementa a lista de indices para o bulkInsert no banco já ordenada pela frequencia
foreach (var iDic in dicIndice.OrderByDescending(d =>d.Value))
{
INDICE indice = new INDICE();
indice.IND_DOCUMENTO = Documento.DOC_ID;
indice.IND_VOCABULARIO = iDic.Key.VOC_ID;
indice.IND_FREQUENCIA = iDic.Value;
indices.Add(indice);
}
_indiceRepositorio.InsereBulkIndice(indices);
}
示例2: sortArray
//Sort list by frequency
public static List<int> sortArray(int[] arr){ //Time:O(nlogn), Space:O(n)
//Handle edge case
if (arr.Length == 0)
return null;
Dictionary<int, Element> dt = new Dictionary<int, Element> ();
for (int i = 0; i < arr.Length; i++) { //put all info into dt, Time: O(n)
if (dt.ContainsKey (arr [i])) {
dt [arr [i]].occurence++;
} else {
Element temp = new Element (1, i);
dt.Add (arr [i], temp);
}
}
//sort object in dt by occurence in descending order then by firstIndex in ascending order
//use QuickSort, time: O(nlogn)
List<KeyValuePair<int, Element>> sortedList = dt.OrderByDescending (o => o.Value.occurence).
ThenBy (o => o.Value.firstIndex).ToList ();
//Convert the sortedList to a result list
List<int> result = new List<int> ();
foreach (KeyValuePair<int, Element> kp in sortedList) {
for (int i = 0; i < kp.Value.occurence; i++)
result.Add (kp.Key);
}
return result;
}
示例3: EventCategory
internal EventCategory(int categoryID)
{
this.categoryID = categoryID;
this.events = new Dictionary<RoomData, int>();
this.orderedEventRooms = events.OrderByDescending(t => t.Value);
this.addQueue = new Queue();
this.removeQueue = new Queue();
this.updateQueue = new Queue();
}
示例4: PrintResults
public static void PrintResults(string methodName, Dictionary<string, double> reports)
{
Console.WriteLine("Results for {0} method in milliseconds:", methodName);
var results = reports.OrderByDescending(x => x.Value);
int index = 1;
foreach (var res in results)
{
Console.WriteLine("{0}.{1} - {2}", index++, res.Key, res.Value);
}
Console.WriteLine();
}
示例5: RoomCategory
public RoomCategory(int categoryID, string caption)
{
this.categoryID = categoryID;
this.caption = caption;
this.activeRooms = new Dictionary<RoomData, int>();
this.orderedRooms = activeRooms.OrderByDescending(t => t.Value).Take(0);
this.addActiveRoomQueue = new Queue();
this.updateActiveRoomQueue = new Queue();
this.removeActiveRoomQueue = new Queue();
}
示例6: EventManager
public EventManager()
{
this.eventCategories = new Dictionary<int, EventCategory>();
this.events = new Dictionary<RoomData, int>();
this.orderedEventRooms = events.OrderByDescending(t => t.Value);
this.addQueue = new Queue();
this.removeQueue = new Queue();
this.updateQueue = new Queue();
for (int i = 0; i < 30; i++)
{
eventCategories.Add(i, new EventCategory(i));
}
}
示例7: EventManager
/// <summary>
/// Initializes a new instance of the <see cref="EventManager" /> class.
/// </summary>
public EventManager()
{
_eventCategories = new Dictionary<int, EventCategory>();
_events = new Dictionary<RoomData, uint>();
_orderedEventRooms = _events.OrderByDescending(t => t.Value);
_addQueue = new Queue();
_removeQueue = new Queue();
_updateQueue = new Queue();
for (int i = 0; i < 30; i++)
_eventCategories.Add(i, new EventCategory(i));
}
示例8: SaveData
public void SaveData(Dictionary<string, int> dict, int len)
{
ArrayList list = new ArrayList();
FileStream fs = new FileStream(string.Format("result_{0}word.txt", len), FileMode.OpenOrCreate, FileAccess.Write);
fs.SetLength(0);
StreamWriter write = new StreamWriter(fs);
List<KeyValuePair<string ,int>> data = dict.OrderByDescending(x => x.Value).ToList();
foreach (KeyValuePair<string, int> kv in data)
{
write.WriteLine(kv.Key + " " + kv.Value);
}
write.Close();
fs.Close();
}
示例9: SortScores
private Dictionary<String, int> SortScores(string[] scores, int count)
{
string[] split;
Dictionary<String, int> scoreDic = new Dictionary<string,int>();
Dictionary<String, int> tempDic = new Dictionary<string, int>();
for (int i = 0; i < count ; i++)
{
split = scores[i].Split(' ');
scoreDic.Add(split[0] + i.ToString(), int.Parse(split[1]));
}
tempDic = scoreDic.OrderByDescending(x => x.Value).ToDictionary(pair => pair.Key, pair => pair.Value);
return (Dictionary<String, int>)tempDic;
}
示例10: Process
public static string Process(Index index, string[] query)
{
_index = index;
// initialize the rank dictionary
Dictionary<int, double> rank = new Dictionary<int, double>();
foreach (KeyValuePair<int, string> document in _index.documents)
rank.Add(document.Key, 0.0);
// rank the terms in the query
Dictionary<string, double> queryWeight = new Dictionary<string, double>();
int weight = 1;
foreach (string term in query.Reverse())
{
queryWeight.Add(term, weight);
// weight++;
}
// loop through all of the terms in the index
foreach (KeyValuePair<int, string> term in _index.terms)
{
// only process the terms that are being queried
if (query.Contains(term.Value) == true)
{
// loop though all of the documents in the index
foreach (KeyValuePair<int, string> document in _index.documents)
{
int frequency = Occurrences(document.Value, term.Value);
// only process the documents that contain this term
if (frequency > 0)
rank[document.Key] = rank[document.Key] + ComputeWeight(document.Key, term.Key, frequency, queryWeight[term.Value]);
}
}
}
// calculate the results
StringBuilder sb = new StringBuilder();
foreach (KeyValuePair<int, double> result in rank.OrderByDescending(z => z.Value))
{
sb.AppendLine(result.Key.ToString() + " " + result.Value.ToString());
}
return sb.ToString();
}
示例11: GetDistribution
public override IEnumerable GetDistribution(Release[] releases)
{
Dictionary<string, int> result = new Dictionary<string, int>();
foreach (Release release in releases)
{
if (!string.IsNullOrEmpty(release.Genre))
{
if (!result.ContainsKey(release.Genre))
{
result[release.Genre] = 0;
}
++result[release.Genre];
}
}
var allItems = result.OrderByDescending(i => i.Value);
var topItems = allItems.Take(6);
var otherItems = allItems.Skip(6);
int otherItemsSum = otherItems.Sum(i => i.Value);
foreach (var topItem in topItems)
{
yield return new Item()
{
Key = topItem.Key + " (" + topItem.Value + ")",
Value = topItem.Value,
Genres = new string[] { topItem.Key },
};
}
if (otherItemsSum != 0)
{
yield return new Item()
{
Key = "Other (" + otherItemsSum + ")",
Value = otherItemsSum,
Genres = otherItems.Select(i => i.Key).ToArray()
};
}
}
示例12: Main
static void Main(string[] args)
{
foreach (String name in Directory.GetFiles(_picturesDirectory, "*.jpg"))
_knownNames.Add(name);
Dictionary<DateTime, string> nameDic = new Dictionary<DateTime, string>();
foreach (String name in _knownNames)
nameDic.Add(Directory.GetCreationTime(name), name);
var lastime = nameDic.Count() > 0 ? nameDic.Last().Key : DateTime.Now;
StreamReader r = new StreamReader(_picturesDirectory + "\\list.txt");
String line;
while ((line = r.ReadLine()) != null)
{
nameDic.Add(lastime, line);
lastime = lastime.AddSeconds(1);
}
foreach (var item in nameDic.OrderByDescending(x=>x.Key))
FindFollowers(
String.Format("https://api.twitter.com/1/followers/[email protected]{0}", Path.GetFileNameWithoutExtension(item.Value)));
}
示例13: BuildDetailedStatsByCapReport
private void BuildDetailedStatsByCapReport(StringBuilder sb, string capName)
{
sb.AppendFormat("Capability name {0}\n", capName);
ConsoleDisplayTable cdt = new ConsoleDisplayTable();
cdt.AddColumn("User Name", 34);
cdt.AddColumn("Req Received", 12);
cdt.AddColumn("Req Handled", 12);
cdt.Indent = 2;
Dictionary<string, int> receivedStats = new Dictionary<string, int>();
Dictionary<string, int> handledStats = new Dictionary<string, int>();
m_scene.ForEachScenePresence(
sp =>
{
Caps caps = m_scene.CapsModule.GetCapsForUser(sp.UUID);
if (caps == null)
return;
Dictionary<string, IRequestHandler> capsHandlers = caps.CapsHandlers.GetCapsHandlers();
IRequestHandler reqHandler;
if (capsHandlers.TryGetValue(capName, out reqHandler))
{
receivedStats[sp.Name] = reqHandler.RequestsReceived;
handledStats[sp.Name] = reqHandler.RequestsHandled;
}
else
{
PollServiceEventArgs pollHandler = null;
if (caps.TryGetPollHandler(capName, out pollHandler))
{
receivedStats[sp.Name] = pollHandler.RequestsReceived;
handledStats[sp.Name] = pollHandler.RequestsHandled;
}
}
}
);
foreach (KeyValuePair<string, int> kvp in receivedStats.OrderByDescending(kp => kp.Value))
{
cdt.AddRow(kvp.Key, kvp.Value, handledStats[kvp.Key]);
}
sb.Append(cdt.ToString());
}
示例14: _sortTable
private DataTable _sortTable()
{
int intTempIndex = -1;
string[] astrSort = _strSort.Split(' ');
if (astrSort.Length != 2)
{
throw new Exception("Sort clause in unsupported format: " + _strSort);
}
for (int i = 0; i < this.baseTable.Columns.Count; i++)
{
if (this.baseTable.Columns[i].ColumnName.Equals(astrSort[0], StringComparison.CurrentCultureIgnoreCase))
{
intTempIndex = i;
break;
}
}
if (-1 == intTempIndex)
{
throw new Exception("Column name not found: " + astrSort[0]);
}
DataTable dtReturn = _dupeTableNoData();
switch (this.baseTable.Columns[intTempIndex].DataType.ToString())
{
case "System.Int32":
case "System.String":
case "System.Decimal":
case "System.DateTime":
Dictionary<int, IComparable> dictRowNumThenIntValue = new Dictionary<int, IComparable>();
for (int i=0; i < this.baseTable.Rows.Count; i++)
{
dictRowNumThenIntValue.Add(i, (IComparable)this.baseTable.Rows[i][intTempIndex]);
}
if (astrSort[1].Equals("DESC", StringComparison.CurrentCultureIgnoreCase))
foreach (KeyValuePair<int, IComparable> rowNumThenValue in dictRowNumThenIntValue.OrderByDescending(entry => entry.Value))
dtReturn.Rows.Add(_copyRow(dtReturn.NewRow(), dtReturn.Columns, rowNumThenValue.Key));
else if (astrSort[1].Equals("ASC", StringComparison.CurrentCultureIgnoreCase))
foreach (KeyValuePair<int, IComparable> rowNumThenValue in dictRowNumThenIntValue.OrderBy(entry => entry.Value))
dtReturn.Rows.Add(_copyRow(dtReturn.NewRow(), dtReturn.Columns, rowNumThenValue.Key));
break;
default:
throw new NotImplementedException(
string.Format(
"Uncaptured data type ({0}) for datatable sort: {1}",
this.baseTable.Columns[intTempIndex].DataType.ToString(),
dtReturn.Columns[intTempIndex].ColumnName
)
);
}
return dtReturn;
}
示例15: initXValues
private Dictionary<object, object> initXValues(ResultPage page, List<ResultCell[]> XDimensions)
{
Dictionary<object, object> result = new Dictionary<object, object>();
bool hasNVD3Pie = Model.Elements.Exists(i => i.SerieDefinition == SerieDefinition.NVD3Serie && i.Nvd3Serie == NVD3SerieDefinition.PieChart && i.PivotPosition == PivotPosition.Data);
bool orderAsc = true;
foreach (var dimensions in XDimensions)
{
//One value -> set the raw value, several values -> concat the display value
if (dimensions.Length == 1)
{
if (!dimensions[0].Element.IsEnum && dimensions[0].Element.AxisUseValues && !hasNVD3Pie)
{
result.Add(dimensions, dimensions[0].Value);
}
else
{
result.Add(dimensions, dimensions[0].ValueNoHTML);
}
}
else result.Add(dimensions, Helper.ConcatCellValues(dimensions, ","));
if (dimensions.Length > 0 && dimensions[0].Element.SortOrder.Contains(SortOrderConverter.kAutomaticDescSortKeyword)) orderAsc = false;
}
return orderAsc ? result.OrderBy(i => i.Value).ToDictionary(i => i.Key, i => i.Value) : result.OrderByDescending(i => i.Value).ToDictionary(i => i.Key, i => i.Value);
}