本文整理汇总了C#中SortedList.Where方法的典型用法代码示例。如果您正苦于以下问题:C# SortedList.Where方法的具体用法?C# SortedList.Where怎么用?C# SortedList.Where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedList
的用法示例。
在下文中一共展示了SortedList.Where方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Tarjeta
/// <summary>
/// Crea una nueva instancia de clase Tarjeta
/// </summary>
/// <param name="device">Instancia de tarjeta</param>
internal Tarjeta(Device device)
{
//this.device = device;
// Lista de la tareas
tareas = new Dictionary<string, Task>();
try
{
// Emulador
emulador = device.IsSimulated;
// Canales digitales
canalesDigitales = new SortedList<string, int>();
foreach (var canal in device.DILines)
{
canalesDigitales.Add(canal, 1);
}
// Puertos digitales
puertosDigitales = new SortedList<string, int>();
foreach (var puerto in device.DIPorts)
{
puertosDigitales.Add(puerto, canalesDigitales.Where((x) => x.Key.StartsWith(puerto)).Count());
}
}
catch (DaqException ex)
{
throw new DriverException(ex);
}
}
示例2: listMessages
public static void listMessages(SortedList<int, Mail> listMessages)
{
Console.WriteLine("\nYour Messages:");
Console.WriteLine("____________________________________________");
foreach (var item in listMessages.Where( message => message.Value.Sender == Settings.theSetting.Sender))
{
int key = item.Key;
Mail bm = item.Value;
if (bm.isSeen == false)
{
Console.ForegroundColor = ConsoleColor.DarkBlue;
Console.WriteLine("\nThis message is new");
//Console.ResetColor();
}
Console.WriteLine("\nMail number: " + key);
Console.Write("\nFrom: " + bm.Sender + " ");
Console.Write("Title: " + bm.Subject + "\n");
Console.Write("Inkom: " + bm.Time + "\n\n");
Console.WriteLine("____________________________________________");
Console.ResetColor();
}
}
示例3: LineIsCode
private bool LineIsCode(ITextRunConstructionContext context, SortedList<int, object> content)
{
if (content.IsNull())
return false;
var codeLines = content.Where(x => !(x.Value is string)).Select(x => x.Key);
var line = context.VisualLine.LastDocumentLine.LineNumber;
if (codeLines.Contains(line))
return true;
return false;
}
示例4: AddButtons
void AddButtons()
{
PhraseOfCollectMode CurrentPhrase = new PhraseOfCollectMode(LearningItem.CurrentSub);
// find analogue
List<PhraseOfCollectMode> analogue = LearningItem.MainSubs.PhrasesList.FindAll(x => x.Words.Count == CurrentPhrase.Words.Count);
if (analogue.Count < 3){
analogue = LearningItem.MainSubs.PhrasesList.FindAll(
x => ((x.Words.Count >= CurrentPhrase.Words.Count - 1) && (x.Words.Count <= CurrentPhrase.Words.Count + 1)));
if (analogue.Count < 3)
{
analogue = LearningItem.MainSubs.PhrasesList;
}
}
// a list of phrases
Random rnd = new Random();
SortedList<int, PhraseOfCollectMode> PhrasesForShow = new SortedList<int, PhraseOfCollectMode>();
PhrasesForShow.Add(rnd.Next(0, 32000), CurrentPhrase);
for (int i = 0; i < 100; i++)
{
if (PhrasesForShow.Count == LearningItem.NumberOfPrasesForUndestandingTest) break;
PhraseOfCollectMode rndphrase = analogue[rnd.Next(0, analogue.Count)];
if (IsEmpty(rndphrase.SubtitleItem.Text2)) continue;
var tlist = PhrasesForShow.Where(x => PhraseOfCollectMode.IsPhraseEqualent(x.Value, rndphrase));
if (tlist.Count() > 0) continue;
PhrasesForShow.Add(rnd.Next(0, 32000), rndphrase);
}
if(PhrasesForShow.Count < LearningItem.NumberOfPrasesForUndestandingTest)
{
DialogService.Message(Tx.T("UnderstandingTest.Messages.NotEnoughPhrases"),Tx.T("Common.Titles.Error"));
return;
}
// Add to panel
ButtonsCollection.Clear();
foreach (var elm in PhrasesForShow)
{
ButtonsCollection.Add(new ButtonModel() {Text = elm.Value.SubtitleItem.Text2,IsItTrue = elm.Value == CurrentPhrase});
}
}
示例5: SetBlobProperties
internal bool SetBlobProperties(string containerName, string blobName, SortedList<string, string> properties)
{
try
{
var container = _client.GetContainerReference(containerName);
var blob = container.GetBlobReference(blobName);
blob.Properties.ContentType = properties.Where((pair, val) => pair.Key == "ContentType").First().Value;
blob.SetProperties();
return true;
}
catch (StorageClientException)
{
return false;
}
}
示例6: ComputeTrend
///returns a value between -1 and 1
///0 is neutral trend, -1= powerful lowering trend
///1 is powerful rising trend
public double ComputeTrend(SortedList<int, double> years, int currentYear)
{
var consideredYears = years.Where(y => y.Key <= currentYear && y.Key > currentYear - 5).Select(y => y.Value).ToList();
if (consideredYears.Count < 3)
{
return 0;
}
double sum = 0;
for (var i = 0; i < consideredYears.Count - 2; i++)//don't take last year value
{
sum += consideredYears[i];
}
var avg = sum / consideredYears.Count - 1;
double difSum = 0;
for (var i = 0; i < consideredYears.Count - 2; i++)//don't take last year value
{
difSum += Math.Pow(consideredYears[i] - avg, 2);
}
var standardDev = Math.Sqrt(difSum / (consideredYears.Count - 1));
var trend = (consideredYears.Last() - avg) / (standardDev); //if indicator moves one standard deviation away, it is considered very powerful trend
if (trend > 1)
{
trend = 1;
}
else if (trend < -1)
{
trend = -1;
}
return trend;
}
示例7: GetSpecNames
public static List<ApiLanguageValuePair> GetSpecNames(string xref, string[] supportedLanguages, SortedList<string, List<SpecViewModel>> specs = null)
{
if (specs != null && specs.Count > 0)
{
return specs.Where(kv => supportedLanguages.Contains(kv.Key)).Select(kv => new ApiLanguageValuePair() { Language = kv.Key, Value = GetSpecName(kv.Value) }).ToList();
}
if (!string.IsNullOrEmpty(xref))
{
return supportedLanguages.Select(s => new ApiLanguageValuePair() { Language = s, Value = xref }).ToList();
}
return null;
}
示例8: ExtractCommonFactors
public static IGate ExtractCommonFactors(IGate gate)
{
var original = gate;
if (gate.Type == GateType.OR)
{
// TraceOptimize("extract common factors from {0} ...", gate);
var sop = gate.GetSOP();
// count how many times each factor appears
var inmap = new Dictionary<int, IInput>();
var dict = new SortedList<int, int>();
foreach (var p in sop.GetPrimitiveFactors())
{
// a gate representing the factors (may be multiple per state variable)
var pg = p.ToGate();
foreach (var i in pg.GetInputs().OfType<IInput>())
{
var address = i.Address;
// TraceOptimize("check factor {0} @ {1:X6}", i, address);
if (!inmap.ContainsKey(i.Address))
{
inmap.Add(i.Address, i);
}
if (!dict.ContainsKey(address))
{
dict[address] = 1;
}
else
{
dict[address]++;
}
}
}
var m = dict.Values.Max();
// TraceOptimize("maximum factor count {0}", m);
if (m > 1)
{
// go for it, take the first input with maximum multiplicity, inputs are ordered.
var pivotindex = dict.Where(e => e.Value == m).Select(e => e.Key).First();
var pivot = inmap[pivotindex];
var pivotlist = new List<Product>();
var otherlist = new List<Product>();
TraceOptimize("use pivot {0:X6} ...", pivot);
// split sop into two groups: factor or not
foreach (var p in sop)
{
if (p.ContainsFactor(pivot))
{
p.RemoveInput(pivot);
pivotlist.Add(p);
}
else
{
otherlist.Add(p);
}
}
IGate and = new ANDGate();
and.AddInput(pivot);
IGate inneror = new ORGate();
foreach (var p in pivotlist)
{
var z = p.ToGate().Simplify();
// Debug.Assert(z.GetInputs().Count() > 1);
Trace("adding pivot {0} [{1}]", z, z.GetType().Name);
inneror.AddInput(z);
}
inneror = ExtractCommonFactors(inneror);
and.AddInput(inneror);
if (otherlist.Any())
{
//var rh = ExtractCommonFactors(otherlist);
var or = new ORGate();
or.AddInput(and);
foreach (var p in otherlist)
{
var z = p.ToGate();
or.AddInput(z.Simplify());
}
//.........这里部分代码省略.........
示例9: GetClusteringQuality_JustIntracluster
/// <summary>
/// Gets the quality of a clustering based upon the intra-cluster distance.
/// </summary>
/// <param name="clustering">cluster id, ids of grouped entities</param>
/// <param name="entities">entity id, entity</param>
/// <returns>A quality measure</returns>
private Return<double> GetClusteringQuality_JustIntracluster(SortedList<int, List<int>> clustering, SortedList<int, Vector<decimal>> entities)
{
Return<double> _answer = new Return<double>();
try
{
SortedList<int, double> _clusterSums = new SortedList<int, double>();
foreach (int _clusterId in clustering.Keys)
{//cluster to cluster
double _clusterSum = 0;
List<Vector<decimal>> _entitiesInTheCluster = entities.Where(kv => clustering[_clusterId].Contains(kv.Key)).Select(kv => kv.Value).ToList();
for (int i = 0; i < _entitiesInTheCluster.Count - 1; i++)
{
for (int j = i + 1; j < _entitiesInTheCluster.Count; j++)
{
Return<decimal> _answerEuclideanDistance = Mathematics.EuclideanDistance(_entitiesInTheCluster[i].values, _entitiesInTheCluster[j].values);
if (_answerEuclideanDistance.theresError)
{
_answer.theresError = true;
_answer.error = _answerEuclideanDistance.error;
}
else
_clusterSum += Math.Pow((double)_answerEuclideanDistance.data, 2);
if (_answer.theresError)
break;
}
if (_answer.theresError)
break;
}
if (!_answer.theresError)
_clusterSums.Add(_clusterId, _clusterSum);
if (_answer.theresError)
break;
}//cluster to cluster
if (!_answer.theresError)
{
double _sum = 0;
foreach (int _clusterId in clustering.Keys)
{//cluster to cluster
int _n = clustering[_clusterId].Count;
double _partialSum = _clusterSums[_clusterId];
_sum += _partialSum / (2 * _n);
}//cluster to cluster
_answer.data = 1 / _sum;
}
}
catch (Exception _ex)
{
_answer.theresError = true;
_answer.error = Utility.GetError(_ex, this.GetType());
}
return _answer;
}
示例10: GetCentroidsAffinityWay2
private Return<SortedList<int, List<int>>> GetCentroidsAffinityWay2(SortedList<int, Vector<decimal>> centroids
, SortedList<int, Vector<decimal>> entities)
{
Return<SortedList<int, List<int>>> _answer = new Return<SortedList<int, List<int>>>() { data = new SortedList<int, List<int>>() };
try
{
centroids.Keys.ToList().ForEach(i => _answer.data.Add(i, new List<int>()));
foreach (int _objectId in entities.Keys)
{//objectId to objectId
if (!_answer.data.SelectMany(a => a.Value).Contains(_objectId))
{//the object has not been grouped yet
Vector<decimal> _vectorEntity = entities[_objectId];
//_centroidId, EuclideanDistance
List<Tuple<int, decimal>> _distance = new List<Tuple<int, decimal>>();
foreach (int _centroidId in centroids.Keys)
{//centroid to centroid
Vector<decimal> _vectorCentroid = centroids[_centroidId];
Return<decimal> _answerEuclideanDistance = Mathematics.EuclideanDistance(_vectorEntity.values, _vectorCentroid.values);
if (_answerEuclideanDistance.theresError)
{
_answer.theresError = true;
_answer.error = _answerEuclideanDistance.error;
}
else
_distance.Add(new Tuple<int, decimal>(_centroidId, (decimal)_answerEuclideanDistance.data));
if (_answer.theresError)
break;
}//centroid to centroid
if (!_answer.theresError)
{//add object to group
int _closestCentroidID = _distance.OrderBy(d => d.Item2).First().Item1;
_answer.data[_closestCentroidID].Add(_objectId);
}//add object to group
}//the object has not been grouped yet
if (_answer.theresError)
break;
}//objectId to objectId
if (!_answer.theresError)
{//recalculate the centroids
foreach (int _centroidId in _answer.data.Keys)
{//centroid to centroid
List<Vector<decimal>> _vectorsOfTheGroup = entities.Where(kv => _answer.data[_centroidId].Contains(kv.Key)).Select(kv => kv.Value).ToList();
int _countCharacteristics = _vectorsOfTheGroup.First().length;
Vector<decimal> _newCentroid = new Vector<decimal>(_centroidId, new decimal[_countCharacteristics]);
for (int _indexCharacteristic = 0; _indexCharacteristic < _countCharacteristics; _indexCharacteristic++)
{//characteristic to characteristic
List<decimal> _ofAllObjects = _vectorsOfTheGroup.Select(v => v[_indexCharacteristic]).ToList();
Return<decimal> _answerArithmeticMean = Mathematics.ArithmeticMean(_ofAllObjects);
if (_answerArithmeticMean.theresError)
{
_answer.theresError = true;
_answer.error = _answerArithmeticMean.error;
}
else
_newCentroid[_indexCharacteristic] = _answerArithmeticMean.data;
if (_answer.theresError)
break;
}//characteristic to characteristic
if (!_answer.theresError)
centroids[_centroidId] = _newCentroid;
if (_answer.theresError)
break;
}//centroid to centroid
}//recalculate the centroids
}
catch (Exception _ex)
{
_answer.theresError = true;
_answer.error = Utility.GetError(_ex, this.GetType());
}
return _answer;
}
示例11: IterativeFind
/// <summary>
/// Perform a Kademlia iterativeFind* operation.
/// If getValue is true, it sends out a list of strings if values are found, or null none are.
/// </summary>
/// <param name="target"></param>
/// <param name="getValue">true for FindValue, false for FindNode</param>
/// <param name="vals"></param>
/// <returns></returns>
private IterativeFindResult IterativeFind(ID target, bool getValue)
{
IterativeFindResult result = new IterativeFindResult();
// Log the lookup
if (target != routingTable.OurContact.GetID())
routingTable.Touch(target);
// Get the alpha closest nodes to the target
var shortlist = new SortedList<ID, HaveAsked>();
foreach (Contact c in routingTable.CloseContacts(20, target))
shortlist.Add(c.GetID() ^ target, new HaveAsked() { Contact = c, Asked = false });
// Until we run out of people to ask or we're done...
bool peersLeftToAsk = true;
while (peersLeftToAsk)
{
var closestPeerNotAsked = shortlist.Where(x => x.Value.Contact.GetID() != myself.GetID() && !x.Value.IsNotContactable) //Don't ask myself, ignore not contactable nodes
.Take(3) //only consider the first 3 closest nodes
.Where(x => x.Value.Asked == false) //That we haven't asked before
.FirstOrDefault(); //Get the first
if (closestPeerNotAsked.Value == null)
{
peersLeftToAsk = false;
continue;
}
result.NumberIterations += 1;
closestPeerNotAsked.Value.Asked = true;
var remotePeerUri = closestPeerNotAsked.Value.Contact.ToUri();
var peer = serverFactory(remotePeerUri);
SearchResult searchResult;
if (getValue)
searchResult = peer.FindValue(myself, target.Data);
else
searchResult = peer.FindNode(myself, target.Data);
//peer is down, ignore
if (searchResult == null)
{
closestPeerNotAsked.Value.IsNotContactable = true;
continue;
}
if (searchResult.Values != null)
{
result.Values = searchResult.Values;
result.TargetPeer = closestPeerNotAsked.Value.Contact;
return result;
}
if (searchResult.Contacts != null)
{
// Add suggestions to shortlist and check for closest
foreach (Contact suggestion in searchResult.Contacts)
{
var distance = suggestion.GetID() ^ target;
if (!shortlist.ContainsKey(distance))
shortlist.Add(distance, new HaveAsked() { Contact = suggestion });
//Add this guy to our contact cache
routingTable.AddContact(suggestion);
}
}
}
result.ClosestPeers = shortlist.Values.Where(x => !x.IsNotContactable).Select(x => x.Contact).Take(20).ToList();
return result;
}
示例12: IOLinks_PreMergeBrains
/// <summary>
/// This finds brains that are really close together, and turns them into sets (the rest of the brains become 1 item sets)
/// </summary>
internal static Set2D[] IOLinks_PreMergeBrains(Item2D[] brains, SortedList<Tuple<int, int>, double> links)
{
if (!IOPREMERGE_SHOULD)
{
return Enumerable.Range(0, brains.Length).Select(o => new Set2D(o, brains)).ToArray();
}
// Get the AABB of the brains, and use the diagonal as the size
var aabb = Math2D.GetAABB(brains.Select(o => o.Position));
double maxDistance = (aabb.Item2 - aabb.Item1).Length;
// Figure out the max distance allowed for a merge
double threshold = maxDistance * IOPREMERGE_DISTANCE;
// Find links that should be merged
var closePairs = links.
Where(o => o.Value <= threshold).
OrderBy(o => o.Value).
ToArray();
if (closePairs.Length == 0)
{
return Enumerable.Range(0, brains.Length).Select(o => new Set2D(o, brains)).ToArray();
}
// Combine any close pairs that share a point (turn pairs into triples)
List<List<int>> sets = IOLinks_PreMergeBrains_Sets(closePairs);
// Build the final list
return IOLinks_PreMergeBrains_Centers(sets, brains, links);
}