本文整理汇总了C#中SortedDictionary.Last方法的典型用法代码示例。如果您正苦于以下问题:C# SortedDictionary.Last方法的具体用法?C# SortedDictionary.Last怎么用?C# SortedDictionary.Last使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedDictionary
的用法示例。
在下文中一共展示了SortedDictionary.Last方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateMedianSum
public static int CalculateMedianSum(int[] numbers)
{
int medianSum = 0;
var lowHeap = new SortedDictionary<int, int>();
var highHeap = new SortedDictionary<int, int>();
lowHeap.Add(numbers[0],0);
medianSum += numbers[0];
for (int index = 1; index < numbers.Length; index++)
{
int lowHeapMax = lowHeap.Last().Key;
int current = numbers[index];
// update heaps
if (current < lowHeapMax)
{
lowHeap.Add(current,0);
}
else
{
highHeap.Add(current, 0);
}
bool mayRequireBalancing = (index + 1)%2 == 0;
// balancing
if (mayRequireBalancing && lowHeap.Count != highHeap.Count)
{
if (lowHeap.Count > highHeap.Count)
{
lowHeapMax = lowHeap.Last().Key;
lowHeap.Remove(lowHeapMax);
highHeap.Add(lowHeapMax, 0);
}
else
{
int highHeapMin = highHeap.First().Key;
highHeap.Remove(highHeapMin);
lowHeap.Add(highHeapMin, 0);
}
}
// calculate median
if (lowHeap.Count >= highHeap.Count)
{
medianSum += lowHeap.Last().Key;
}
else
{
medianSum += highHeap.First().Key;
}
}
return medianSum;
}
示例2: Account
public Account(string userName, Currency currency, SortedDictionary<DateTime, Trasaction> transactionHistory)
{
this.userName = userName;
this.currency = currency;
this.transactionHistory = transactionHistory;
this.balance = transactionHistory.Last().Value.GetBalance();
}
示例3: GetPosition
private Vector2 GetPosition(Identifier512 id, SortedDictionary<Identifier512, Peer> peers)
{
Peer end;
if (!peers.TryGetValue(id, out end))
end = peers.Where(a => a.Key >= id).Select(a => a.Value).FirstOrDefault() ?? peers.Last().Value;
return end.Position;
}
示例4: Main
static void Main()
{
Thread.CurrentThread.CurrentCulture = new CultureInfo("bg-BG");
DateTime currentDateTime = DateTime.Parse(Console.ReadLine());
SortedDictionary<DateTime, string> text = new SortedDictionary<DateTime, string>();
var input = Console.ReadLine();
while (input != "END")
{
string pattern = @"(.+)(\s\/\s)(\d{2}-\d{2}-\d{4}\s\d{2}:\d{2}:\d{2})";
Regex rgx = new Regex(pattern);
MatchCollection matches = rgx.Matches(input);
string firstGroup = "";
DateTime thisDateTime = DateTime.MinValue;
foreach (Match match in matches)
{
firstGroup = match.Groups[1].Value;
thisDateTime = DateTime.Parse(match.Groups[3].Value);
}
text.Add(thisDateTime, firstGroup);
input = Console.ReadLine();
}
string timestamp = "";
DateTime mostRecentDate = text.Last().Key;
if ((currentDateTime - mostRecentDate).TotalHours < 1 && (currentDateTime - mostRecentDate).TotalMinutes >= 1 )
{
string minutes = (int)(currentDateTime - mostRecentDate).TotalMinutes + " " + "minute(s) ago";
timestamp = minutes;
}
else if ((currentDateTime.Day == mostRecentDate.Day) && (currentDateTime - mostRecentDate).TotalHours >= 1)
{
string hour = (int)(currentDateTime - mostRecentDate).TotalHours + " " + "hour(s) ago";
timestamp = hour;
}
else if (mostRecentDate.Day == currentDateTime.Day - 1)
{
timestamp = "yesterday";
}
else if ((currentDateTime - mostRecentDate).TotalDays > 1)
{
timestamp = mostRecentDate.ToString("dd-MM-yyyy");
}
else
{
timestamp = "a few moments ago";
}
foreach (var sentence in text)
{
Console.WriteLine("<div>{0}</div>", SecurityElement.Escape(sentence.Value));
}
Console.WriteLine("<p>Last active: <time>{0}</time></p>", timestamp);
}
示例5: Main
static void Main()
{
string inputDare = Console.ReadLine();
var now = GetValue(inputDare);
SortedDictionary<DateTime, string> messegeDictionary = new SortedDictionary<DateTime, string>();
string line = String.Empty;
while ((line = Console.ReadLine()) != "END")
{
string[] temp = line.Split('/');
string messege = temp[0].Trim();
string dateForMessege = temp[1].Trim();
var dateMessege = GetValue(dateForMessege);
messegeDictionary.Add(dateMessege, messege);
}
foreach (var pair in messegeDictionary)
{
Console.WriteLine("<div>{0}</div>", SecurityElement.Escape(pair.Value));
}
var lastActivity = messegeDictionary.Last().Key;
TimeSpan time = now - lastActivity;
if ((now.Day - 1) > lastActivity.Day)
{
Console.WriteLine("<p>Last active: <time>{0:dd-MM-yyyy}</time></p>", messegeDictionary.Last().Key);
return;
}
if (lastActivity.Day == now.Day - 1)
{
Console.WriteLine("<p>Last active: <time>yesterday</time></p>");
return;
}
if (lastActivity.Day == now.Day && time.TotalHours >= 1)
{
Console.WriteLine("<p>Last active: <time>{0} hour(s) ago</time></p>", (int)time.TotalHours);
}
else if (time.TotalHours < 1 && time.TotalMinutes >= 1)
{
Console.WriteLine("<p>Last active: <time>{0} minute(s) ago</time></p>", (int)time.TotalMinutes);
}
else
{
Console.WriteLine("<p>Last active: <time>a few moments ago</time></p>");
}
}
示例6: FillGlobalResultCC
protected override void FillGlobalResultCC()
{
SortedDictionary<double, double> rValues = new SortedDictionary<double, double>();
for (int i = 0; i < assemblyToAnalyze.Count; ++i)
{
int instanceCount = assemblyToAnalyze[i].Results.Count;
for (int j = 0; j < instanceCount; ++j)
{
double index = (rValues.Count != 0) ? rValues.Last().Key : 0;
rValues.Add(index + 1, assemblyToAnalyze[i].Results[j].CoefficientGlobal);
}
}
result.result.Add(AnalyseOptions.ClusteringCoefficient, GetAverageValuesByDelta(rValues));
result.resultValues.Add(AnalyseOptions.ClusteringCoefficient, rValues);
}
示例7: CalculateReduction
public SortedDictionary<double, double> CalculateReduction(SortedDictionary<double, double> input, double percentage)
{
if (input.Count <= 2)
{
return input;
}
else if (percentage<= 0)
{
var first = input.First();
var last = input.Last();
return new SortedDictionary<double, double>() { {first.Key, first.Value}, {last.Key,last.Value} };
}
var m = new MathFunctions();
var temp = (from n in input select new Point(n.Key, n.Value)).ToList();
var result = temp.ToList();
var points = temp.Count;
double factor = 1.5;
double calcfactor = Math.Max(1.5, lastfactor / (factor * factor));
var euclistx = new List<double>();
for (int i = 0; i < temp.Count - 1; i++)
{
euclistx.Add(Math.Sqrt((temp[i].X - temp[i + 1].X) * (temp[i].X - temp[i + 1].X)));
}
var thresholdx = Convert.ToDouble(euclistx.Average());
var thresh = GetAveragePerpendicularDistance(temp);
var xpercentage = 1.0;
var difftotal = m.CalculateDifference(temp, new List<Point>() { temp.First(), temp.Last() });
while (xpercentage > percentage)
{
//var intermediate = m.DouglasPeuckerReduction(temp, calcfactor * thresh);
var intermediate = m.DouglasPeuckerReductionNoStack(temp, calcfactor * thresh);
calcfactor = calcfactor * factor;
lastfactor = calcfactor;
var diff = m.CalculateDifference(temp, intermediate);
xpercentage = 1 - (diff / difftotal);
if (xpercentage > percentage)
result = intermediate.ToList();
}
var resultdict = new SortedDictionary<double, double>();
foreach ( var n in result)
resultdict.Add(n.X,n.Y);
return resultdict;
}
示例8: ApplyShortestDistanceToAdjacentsOfNewAddition
private void ApplyShortestDistanceToAdjacentsOfNewAddition(Dictionary<int, AStarNodeCapsule> capsuleMap, SortedDictionary<int, SortedDictionary<int, AStarNodeCapsule>> closedList, SortedDictionary<int, SortedDictionary<int, AStarNodeCapsule>> openList)
{
AStarNodeCapsule newAddition = closedList.Last().Value.Last().Value;
foreach (Edge edge in newAddition.Node.Edges)
{
AStarNodeCapsule adjacent = GetAdjacent(capsuleMap, newAddition, edge);
int possibleNewShortestDistance = (int)newAddition.ShortestDistance + edge.Cost;
if (adjacent.ShortestDistance == null)
{
adjacent.ShortestDistance = possibleNewShortestDistance;
adjacent.PreviousRouteNode = newAddition;
adjacent.PreviousRouteEdge = edge;
AddNodeCapsuleToOpenList(openList, adjacent);
}
else if ((int)adjacent.ShortestDistance > possibleNewShortestDistance)
{
RemoveNodeCapsuleFromOpenList(openList, adjacent);
adjacent.ShortestDistance = possibleNewShortestDistance;
adjacent.PreviousRouteNode = newAddition;
adjacent.PreviousRouteEdge = edge;
AddNodeCapsuleToOpenList(openList, adjacent);
}
}
}
示例9: GetGlobalAverage
private double GetGlobalAverage(SortedDictionary<double, double> resultDictionary)
{
if (resultDictionary.Count != 0)
return resultDictionary.Last().Value;
else
return 0;
}
示例10: GetGenerationNumber
// Retrieves the current generation number from a collection of the existing resources in the group
private int GetGenerationNumber(SortedDictionary<int, IResource> resources)
{
int number;
if (!resources.Any())
{
number = 0;
}
else if (resources.ContainsKey(Max - 1) && resources.ContainsKey(0))
{
number = 0;
while (resources.ContainsKey(number + 1))
{
number++;
}
}
else
{
number = resources.Last().Key;
}
return number;
}
示例11: GetLatestInternal
private static SortedDictionary<Number640, Data> GetLatestInternal(SortedDictionary<Number640, Data> tmp)
{
// delete all predecessors
var result = new SortedDictionary<Number640, Data>();
while (tmp.Count != 0)
{
// first entry is a latest version
var latest = tmp.Last(); // TODO check if correct
// store in results list
result.Add(latest.Key, latest.Value);
// delete all predecessors of latest entry
DeletePredecessors(latest.Key, tmp);
}
return result;
}
示例12: FillGlobalResult
private void FillGlobalResult(AnalyseOptions option)
{
SortedDictionary<double, double> rValues = new SortedDictionary<double, double>();
for (int i = 0; i < assemblyToAnalyze.Count; ++i)
{
int instanceCount = assemblyToAnalyze[i].Results.Count;
for (int j = 0; j < instanceCount; ++j)
{
double index = (rValues.Count != 0) ? rValues.Last().Key : 0;
rValues.Add(index + 1, assemblyToAnalyze[i].Results[j].Result[option]);
}
}
result.result.Add(option, GetAverageValuesByDelta(rValues));
result.resultValues.Add(option, rValues);
}
示例13: Main
static void Main(string[] args)
{
int nc = int.Parse(Console.ReadLine());
for (int i = 0; i < nc; i++)
{
string [] kn = Console.ReadLine().Split(' ');
string [] abcr = Console.ReadLine().Split(' ');
int n = int.Parse(kn[0]);
int k = int.Parse(kn[1]);
int a = int.Parse(abcr[0]);
int b = int.Parse(abcr[1]);
int c = int.Parse(abcr[2]);
int r = int.Parse(abcr[3]);
List<int> v = new List<int>();
SortedDictionary<int, Counter> sd = new SortedDictionary<int, Counter>();
long m = a;
v.Add(a);
sd.Add(a, new Counter());
for (int j = 1; j < k; j++)
{
m = (b * m + c) % r;
v.Add((int)m);
Counter cv;
if (sd.TryGetValue((int)m, out cv))
{
cv.Inc();
}
else
{
sd.Add((int)m, new Counter());
}
}
CleanUp(ref sd, k + 1);
HashSet<int> active = new HashSet<int>(sd.Keys);
int l = 0;
int p = 0;
int next_p = int.MaxValue;
while (true)
{
if (active.Contains(p))
p = FindNext(sd);
next_p = int.MaxValue;
if (p == k && (sd.First().Key == 0) && (sd.Last().Key == k-1))
{
// We have all values in [0..k-1], there is no need to search for other values
int f;
long ma = ((long)(n-k)) % ((long)k * (long)(k+1));
for (int o = 0; o < ma; o++, l++)
{
l = l % v.Count;
f = v[l];
v[l] = p;
p = f;
}
if (l > 0)
p = v[l - 1];
else
p = v[v.Count - 1];
break;
}
if (l < v.Count)
{
l++;
}
else
{
l = 1;
}
Counter cv;
if (sd.TryGetValue(v[l - 1], out cv))
{
cv.Dec();
if (cv.Value == 0)
{
if (p > v[l - 1])
{
next_p = v[l - 1];
}
active.Remove(v[l - 1]);
sd.Remove(v[l - 1]);
}
}
//if (sd.TryGetValue((int)p, out cv))
//.........这里部分代码省略.........
示例14: PutAll
public IDictionary<Number640, Enum> PutAll(SortedDictionary<Number640, Data> dataMap, IPublicKey publicKey, bool putIfAbsent, bool domainProtection,
bool sendSelf)
{
if (dataMap.Count == 0)
{
return Convenient.EmptyDictionary<Number640, Enum>();
}
var min = dataMap.First().Key; // TODO check if correct
var max = dataMap.Last().Key;
var retVal = new Dictionary<Number640, Enum>();
var keysToCheck = new HashSet<Number480>();
var rangeLock = Lock(min, max);
try
{
foreach (var kvp in dataMap)
{
var key = kvp.Key;
keysToCheck.Add(key.LocationAndDomainAndContentKey);
var newData = kvp.Value;
if (!SecurityDomainCheck(key.LocationAndDomainKey, publicKey, publicKey, domainProtection))
{
retVal.Add(key, PutStatus.FailedSecurity);
continue;
}
// We need this check in case we did not use the encoder/deconder,
// which is the case if we send the message to ourself. In that
// case, the public key of the data is never set to the message
// publick key, if the publick key of the data was null.
IPublicKey dataKey;
if (sendSelf && newData.PublicKey == null)
{
dataKey = publicKey;
}
else
{
dataKey = newData.PublicKey;
}
if (!SecurityEntryCheck(key.LocationAndDomainAndContentKey, publicKey, dataKey, newData.IsProtectedEntry))
{
retVal.Add(key, PutStatus.FailedSecurity);
continue;
}
var contains = _backend.Contains(key);
if (contains)
{
if(putIfAbsent)
{
retVal.Add(key, PutStatus.FailedNotAbsent);
continue;
}
var oldData = _backend.Get(key);
if(oldData.IsDeleted)
{
retVal.Add(key, PutStatus.Deleted);
continue;
}
if(!oldData.BasedOnSet.Equals(newData.BasedOnSet))
{
retVal.Add(key, PutStatus.VersionFork);
continue;
}
}
var oldData2 = _backend.Put(key, newData);
long expiration = newData.ExpirationMillis;
// handle timeout
_backend.AddTimeout(key, expiration);
if(newData.HasPrepareFlag)
{
retVal.Add(key, PutStatus.OkPrepared);
}
else
{
if(newData.Equals(oldData2))
{
retVal.Add(key, PutStatus.OkUnchanged);
}
else
{
retVal.Add(key, PutStatus.Ok);
}
}
}
//now check for forks
foreach (var key in keysToCheck)
{
var minVersion = new Number640(key, Number160.Zero);
var maxVersion = new Number640(key, Number160.MaxValue);
var tmp = _backend.SubMap(minVersion, maxVersion, -1, true);
var heads = GetLatestInternal(tmp);
if(heads.Count > 1)
{
foreach (var fork in heads.Keys)
{
if(retVal.ContainsKey(fork))
{
//.........这里部分代码省略.........
示例15: FillGlobalResultCC
protected override void FillGlobalResultCC()
{
SortedDictionary<double, double> rValues = new SortedDictionary<double, double>();
for (int i = 0; i < assemblyToAnalyze.Count; ++i)
{
int instanceCount = assemblyToAnalyze[i].Results.Count;
for (int j = 0; j < instanceCount; ++j)
{
SortedDictionary<double, int>.KeyCollection keyColl =
assemblyToAnalyze[i].Results[j].Coefficient.Keys;
double sumOfCoeffs = 0;
foreach (double key in keyColl)
{
sumOfCoeffs += key * assemblyToAnalyze[i].Results[j].Coefficient[key];
}
sumOfCoeffs /= assemblyToAnalyze[i].Results[j].Size;
double index = (rValues.Count != 0) ? rValues.Last().Key : 0;
rValues.Add(index + 1, sumOfCoeffs);
}
}
result.result.Add(AnalyseOptions.ClusteringCoefficient, GetAverageValuesByDelta(rValues));
result.resultValues.Add(AnalyseOptions.ClusteringCoefficient, rValues);
}