本文整理汇总了C#中SortedSet.AddAll方法的典型用法代码示例。如果您正苦于以下问题:C# SortedSet.AddAll方法的具体用法?C# SortedSet.AddAll怎么用?C# SortedSet.AddAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedSet
的用法示例。
在下文中一共展示了SortedSet.AddAll方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestMergeRandom
public virtual void TestMergeRandom()
{
PrefixCodedTerms[] pb = new PrefixCodedTerms[TestUtil.NextInt(Random(), 2, 10)];
SortedSet<Term> superSet = new SortedSet<Term>();
for (int i = 0; i < pb.Length; i++)
{
SortedSet<Term> terms = new SortedSet<Term>();
int nterms = TestUtil.NextInt(Random(), 0, 10000);
for (int j = 0; j < nterms; j++)
{
Term term = new Term(TestUtil.RandomUnicodeString(Random(), 2), TestUtil.RandomUnicodeString(Random(), 4));
terms.Add(term);
}
superSet.AddAll(terms);
PrefixCodedTerms.Builder b = new PrefixCodedTerms.Builder();
foreach (Term @ref in terms)
{
b.Add(@ref);
}
pb[i] = b.Finish();
}
List<IEnumerator<Term>> subs = new List<IEnumerator<Term>>();
for (int i = 0; i < pb.Length; i++)
{
subs.Add(pb[i].GetEnumerator());
}
IEnumerator<Term> expected = superSet.GetEnumerator();
IEnumerator<Term> actual = new MergedIterator<Term>(subs.ToArray());
while (actual.MoveNext())
{
Assert.IsTrue(expected.MoveNext());
Assert.AreEqual(expected.Current, actual.Current);
}
Assert.IsFalse(expected.MoveNext());
}
示例2: Routing
/// <summary>
/// Looks for a route to the given peer address.
/// </summary>
/// <param name="peerAddresses">Nodes that should be asked first for a route.</param>
/// <param name="routingBuilder"></param>
/// <param name="type"></param>
/// <param name="cc"></param>
/// <returns>A task object that is set to complete if the route has been found.</returns>
private TcsRouting Routing(ICollection<PeerAddress> peerAddresses, RoutingBuilder routingBuilder,
Message.Message.MessageType type, ChannelCreator cc)
{
try
{
if (peerAddresses == null)
{
throw new ArgumentException("Some nodes/addresses need to be specified.");
}
bool randomSearch = routingBuilder.LocationKey == null;
IComparer<PeerAddress> comparer;
if (randomSearch)
{
comparer = _peerBean.PeerMap.CreateComparer();
}
else
{
comparer = PeerMap.CreateComparer(routingBuilder.LocationKey);
}
var queueToAsk = new SortedSet<PeerAddress>(comparer);
var alreadyAsked = new SortedSet<PeerAddress>(comparer);
// As presented by Kazuyuki Shudo at AIMS 2009, it is better to ask random
// peers with the data than ask peers that are ordered by distance.
// -> this balances load
var directHits = new SortedDictionary<PeerAddress, DigestInfo>(comparer);
var potentialHits = new SortedSet<PeerAddress>(comparer);
// fill initially
queueToAsk.AddAll(peerAddresses);
alreadyAsked.Add(_peerBean.ServerPeerAddress);
potentialHits.Add(_peerBean.ServerPeerAddress);
// domain key can be null if we bootstrap
if (type == Message.Message.MessageType.Request2
&& routingBuilder.DomainKey != null
&& !randomSearch
&& _peerBean.DigestStorage != null)
{
Number640 from;
Number640 to;
if (routingBuilder.From != null && routingBuilder.To != null)
{
from = routingBuilder.From;
to = routingBuilder.To;
}
else if (routingBuilder.ContentKey == null)
{
from = new Number640(routingBuilder.LocationKey, routingBuilder.DomainKey, Number160.Zero, Number160.Zero);
to = new Number640(routingBuilder.LocationKey, routingBuilder.DomainKey, Number160.MaxValue, Number160.MaxValue);
}
else
{
from = new Number640(routingBuilder.LocationKey, routingBuilder.DomainKey, routingBuilder.ContentKey, Number160.Zero);
to = new Number640(routingBuilder.LocationKey, routingBuilder.DomainKey, routingBuilder.ContentKey, Number160.MaxValue);
}
var digestBean = _peerBean.DigestStorage.Digest(from, to, -1, true);
if (digestBean.Size > 0)
{
directHits.Add(_peerBean.ServerPeerAddress, digestBean);
}
}
else if (type == Message.Message.MessageType.Request3
&& !randomSearch
&& _peerBean.DigestTracker != null)
{
var digestInfo = _peerBean.DigestTracker.Digest(routingBuilder.LocationKey, routingBuilder.DomainKey,
routingBuilder.ContentKey);
// we always put ourselfs to the tracker list, so we need to check
// if we know also other peers on our trackers
if (digestInfo.Size > 0)
{
directHits.Add(_peerBean.ServerPeerAddress, digestInfo);
}
}
var tcsRouting = new TcsRouting();
if (peerAddresses.Count == 0)
{
tcsRouting.SetNeighbors(directHits, potentialHits, alreadyAsked, routingBuilder.IsBootstrap, false);
}
else
{
// If a peer bootstraps to itself, then the size of peer addresses is 1
// and it contains itself. Check for that because we need to know if we
// are routing, bootstrapping and bootstrapping to ourselfs, to return
// the correct status for the task.
var isRoutingOnlyToSelf = peerAddresses.Count == 1 &&
peerAddresses.First().Equals(_peerBean.ServerPeerAddress);
var routingMechanism = routingBuilder.CreateRoutingMechanism(tcsRouting);
//.........这里部分代码省略.........
示例3: Merge
/// <summary>
/// Updates queueToAsk with new data, returns if we found peers closer than we already know.
/// </summary>
/// <param name="queueToAsk">The queue to get updated.</param>
/// <param name="newPeers">The new peers reported from remote peers. Since the remote peers
/// do not know what we know, we need to filter this information.</param>
/// <param name="alreadyAsked">The peers we already know.</param>
/// <returns>True, if we added peers that are closer to the target than we already knew.
/// Please note, it will return false if we add new peers that are not closer to a target.</returns>
private static bool Merge(SortedSet<PeerAddress> queueToAsk, ICollection<PeerAddress> newPeers,
ICollection<PeerAddress> alreadyAsked)
{
var result = new SortedSet<PeerAddress>(queueToAsk.Comparer);
Utils.Utils.Difference(newPeers, result, alreadyAsked);
if (result.Count == 0)
{
return false;
}
var first = result.Min;
var isNewInfo = IsNew(queueToAsk, first);
queueToAsk.AddAll(result);
return isNewInfo;
}