本文整理汇总了C#中SortedSet.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# SortedSet.Clear方法的具体用法?C# SortedSet.Clear怎么用?C# SortedSet.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SortedSet
的用法示例。
在下文中一共展示了SortedSet.Clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main()
{
var numberOfDigits = int.Parse(Console.ReadLine());
var digits = new int[numberOfDigits];
for (int i = 0; i < numberOfDigits; i++)
{
digits[i] = int.Parse(Console.ReadLine());
}
Array.Sort(digits);
var allNumbers = new HashSet<int>();
PermuteRep(digits, 0, digits.Length, allNumbers);
var numbersWithMinNumberOfDivisors = new SortedSet<int>();
var minCountOfDivisors = 10000;
foreach (var number in allNumbers)
{
var divisorsCount = CalculateDivisors(number);
if (divisorsCount < minCountOfDivisors)
{
numbersWithMinNumberOfDivisors.Clear();
numbersWithMinNumberOfDivisors.Add(number);
minCountOfDivisors = divisorsCount;
}
else if (divisorsCount == minCountOfDivisors)
{
numbersWithMinNumberOfDivisors.Add(number);
}
}
Console.WriteLine(numbersWithMinNumberOfDivisors.Min);
}
示例2: Analiz
public string Analiz()
{
var names = new SortedSet<string>();
names.Clear();
foreach (
var temp in
from Match match in new Regex("(\\s*\\w[\\w\\d_]*\\s*)(,\\s*\\w[\\w\\d_]*\\s*)*:[^=]").Matches(Text)
select
match.Value.IndexOf(',') >= 0
? match.Value.Substring(0, match.Value.Length - ": ".Length)
.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries)
: new[] {match.Value.Substring(0, match.Value.Length - ": ".Length)})
{
for (var i = 0; i < temp.Count(); i++)
names.Add(temp[i].Trim());
}
if (names.Count < 1) return "Nothing";
var nameArr = names.ToArray();
var variablePoints = new Variable[names.Count];
for (var i = 0; i < variablePoints.Count(); i++)
{
variablePoints[i].Name = nameArr[i];
variablePoints[i].Points = new List<long>();
var nameMatches = new Regex("\\b" + nameArr[i] + "\\b").Matches(Text);
for (var j = 0; j < nameMatches.Count; j++)
variablePoints[i].Points.Add(nameMatches[j].Index);
}
var matchFunc = new Regex(@"(\bprocedure\b|\bfunction\b)\s*(\w*)\s*(\([^)]*\)|)\s*((return\s*\w+\s*|)?is)").Matches(Text);
var func = (from Match match in matchFunc select FindFunc(Text, match)).ToArray();
var list = func[0].Local.ToList();
for (var n = 1; n < func.Count(); n++)
for (var k = 0; k < func[n].Local.Count(); k++)
list.Remove(func[n].Local[k]);
func[0].Local = list.ToArray();
for (var i = 1; i < func.Count(); i++)
{
CountSpen(ref func[i], ref Text);
}
CountSpen(ref func[0], ref Text);
return func.Aggregate(string.Empty,
(current1, function) =>
function.Local.Aggregate(current1 + function.Type + ' ' + function.Name + ":\n",
(current, local) => current + ("\t" + local.Name + " - " + (local.Count - 1) + ";\n")));
}
示例3: TestCopyConstructor2
public static void TestCopyConstructor2()
{
SortedSet<int> sortedSet = new SortedSet<int>();
List<int> listOfItems = new List<int>();
int c = 0;
while (sortedSet.Count < 100000)
{
c++;
if (!sortedSet.Contains(50000 - c))
{
sortedSet.Add(50000 - c);
listOfItems.Add(50000 - c);
}
}
SortedSet<int> newTree1 = new SortedSet<int>(listOfItems);
Assert.True(newTree1.SetEquals(listOfItems)); //"Expected to be the same set."
SortedSet<int> newTree2 = new SortedSet<int>(sortedSet);
Assert.True(newTree2.SetEquals(sortedSet)); //"Expected to be the same set."
IEnumerator<int> t1 = sortedSet.GetEnumerator();
IEnumerator<int> t2 = newTree1.GetEnumerator();
IEnumerator<int> t3 = newTree2.GetEnumerator();
while (t1.MoveNext())
{
t2.MoveNext();
t3.MoveNext();
Assert.Equal(t1.Current, t2.Current); //"Not fully constructed"
Assert.Equal(t2.Current, t3.Current); //"Not fullu constructed."
}
sortedSet.Clear();
}
示例4: TestReverseEnumerator
public static void TestReverseEnumerator()
{
SortedSet<int> sortedSet = new SortedSet<int>();
sortedSet.Clear();
for (int j = 5000; j > 0; j--)
{
if (!sortedSet.Contains(j))
sortedSet.Add(j);
}
int[] output = new int[5000];
sortedSet.CopyTo(output, 0);
int index = 0;
IEnumerator<int> e = sortedSet.Reverse().GetEnumerator();
while (e.MoveNext())
{
int recd = e.Current;
Assert.Equal(recd, output[sortedSet.Count - 1 - index]); //"mismatched reversal"
index++;
}
}
示例5: TryStepForward
public bool TryStepForward()
{
if (_failedForward || _endOfFile)
return false;
if (_input.Index + _lookAheadPosition >= _input.Count)
{
_endOfFile = true;
return false;
}
IToken token = _input.LT(-1 - _lookBehindPosition);
if (token == null)
{
_endOfFile = true;
return false;
}
int symbol = token.Type;
int symbolPosition = token.TokenIndex;
Stopwatch updateTimer = Stopwatch.StartNew();
if (_lookAheadPosition == 0 && _lookBehindPosition == 0 && _contexts.Count == 0)
{
HashSet<InterpretTrace> initialContexts = new HashSet<InterpretTrace>(EqualityComparer<InterpretTrace>.Default);
/* create our initial set of states as the ones at the target end of a match transition
* that contains 'symbol' in the match set.
*/
List<Transition> transitions = new List<Transition>(_network.Transitions.Where(i => i.MatchesSymbol(symbol)));
foreach (var transition in transitions)
{
if (ExcludedStartRules.Contains(Network.StateRules[transition.SourceState.Id]))
continue;
if (ExcludedStartRules.Contains(Network.StateRules[transition.TargetState.Id]))
continue;
ContextFrame startContext = new ContextFrame(transition.SourceState, null, null, this);
ContextFrame endContext = new ContextFrame(transition.SourceState, null, null, this);
initialContexts.Add(new InterpretTrace(startContext, endContext));
}
_contexts.AddRange(initialContexts);
}
List<InterpretTrace> existing = new List<InterpretTrace>(_contexts);
_contexts.Clear();
SortedSet<int> states = new SortedSet<int>();
HashSet<InterpretTrace> contexts = new HashSet<InterpretTrace>(EqualityComparer<InterpretTrace>.Default);
#if false
HashSet<ContextFrame> existingUnique = new HashSet<ContextFrame>(existing.Select(i => i.StartContext), EqualityComparer<ContextFrame>.Default);
Contract.Assert(existingUnique.Count == existing.Count);
#endif
foreach (var context in existing)
{
states.Add(context.EndContext.State.Id);
StepForward(contexts, states, context, symbol, symbolPosition, PreventContextType.None);
states.Clear();
}
bool success = false;
if (contexts.Count > 0)
{
_contexts.AddRange(contexts);
if (TrackBoundedContexts)
_boundedEndContexts.UnionWith(_contexts.Where(i => i.BoundedEnd));
success = true;
}
else
{
_contexts.AddRange(existing);
}
long nfaUpdateTime = updateTimer.ElapsedMilliseconds;
if (success)
_lookAheadPosition++;
if (!success)
_failedForward = true;
return success;
}
示例6: TryStepBackward
public bool TryStepBackward()
{
if (_failedBackward || _beginningOfFile)
return false;
if (_input.Index - _lookBehindPosition <= 0)
{
_beginningOfFile = true;
return false;
}
IToken token = _input.LT(-1 - _lookBehindPosition);
if (token == null)
{
_beginningOfFile = true;
return false;
}
int symbol = token.Type;
int symbolPosition = token.TokenIndex;
/*
* Update the non-deterministic trace
*/
Stopwatch updateTimer = Stopwatch.StartNew();
if (_lookAheadPosition == 0 && _lookBehindPosition == 0 && _contexts.Count == 0)
{
HashSet<InterpretTrace> initialContexts = new HashSet<InterpretTrace>(EqualityComparer<InterpretTrace>.Default);
/* create our initial set of states as the ones at the target end of a match transition
* that contains 'symbol' in the match set.
*/
List<Transition> transitions = new List<Transition>(_network.Transitions.Where(i => i.MatchesSymbol(symbol)));
foreach (var transition in transitions)
{
if (ExcludedStartRules.Contains(Network.StateRules[transition.SourceState.Id]))
continue;
if (ExcludedStartRules.Contains(Network.StateRules[transition.TargetState.Id]))
continue;
ContextFrame startContext = new ContextFrame(transition.TargetState, null, null, this);
ContextFrame endContext = new ContextFrame(transition.TargetState, null, null, this);
initialContexts.Add(new InterpretTrace(startContext, endContext));
}
_contexts.AddRange(initialContexts);
#if DFA
DeterministicState deterministicState = new DeterministicState(_contexts.Select(i => i.StartContext));
_deterministicTrace = new DeterministicTrace(deterministicState, deterministicState);
#endif
}
List<InterpretTrace> existing = new List<InterpretTrace>(_contexts);
_contexts.Clear();
SortedSet<int> states = new SortedSet<int>();
HashSet<InterpretTrace> contexts = new HashSet<InterpretTrace>(EqualityComparer<InterpretTrace>.Default);
#if false
HashSet<ContextFrame> existingUnique = new HashSet<ContextFrame>(existing.Select(i => i.StartContext), EqualityComparer<ContextFrame>.Default);
Contract.Assert(existingUnique.Count == existing.Count);
#endif
foreach (var context in existing)
{
states.Add(context.StartContext.State.Id);
StepBackward(contexts, states, context, symbol, symbolPosition, PreventContextType.None);
states.Clear();
}
bool success = false;
if (contexts.Count > 0)
{
_contexts.AddRange(contexts);
if (TrackBoundedContexts)
_boundedStartContexts.UnionWith(_contexts.Where(i => i.BoundedStart));
success = true;
}
else
{
_contexts.AddRange(existing);
}
long nfaUpdateTime = updateTimer.ElapsedMilliseconds;
#if DFA
/*
* Update the deterministic trace
*/
updateTimer.Restart();
DeterministicTransition deterministicTransition = _deterministicTrace.StartState.IncomingTransitions.SingleOrDefault(i => i.MatchSet.Contains(symbol));
if (deterministicTransition == null)
{
DeterministicState sourceState = new DeterministicState(contexts.Select(i => i.StartContext));
DeterministicState targetState = _deterministicTrace.StartState;
deterministicTransition = targetState.IncomingTransitions.SingleOrDefault(i => i.SourceState.Equals(sourceState));
//.........这里部分代码省略.........
示例7: GetFollowSet
public IntervalSet GetFollowSet()
{
int symbol = UnknownSymbol;
int symbolPosition = _input.Index + _lookAheadPosition - 1;
if (_lookAheadPosition == 0 && _lookBehindPosition == 0 && _contexts.Count == 0)
{
IntervalSet allTokens = new IntervalSet();
foreach (var transition in Network.Transitions.Where(i => i.IsMatch))
allTokens.UnionWith(transition.MatchSet);
return allTokens;
}
Stopwatch updateTimer = Stopwatch.StartNew();
List<InterpretTrace> existing = new List<InterpretTrace>(_contexts);
SortedSet<int> states = new SortedSet<int>();
HashSet<InterpretTrace> contexts = new HashSet<InterpretTrace>(EqualityComparer<InterpretTrace>.Default);
foreach (var context in existing)
{
states.Add(context.EndContext.State.Id);
StepForward(contexts, states, context, symbol, symbolPosition, PreventContextType.None);
states.Clear();
}
IntervalSet result = new IntervalSet();
if (contexts.Count > 0)
{
foreach (var context in contexts)
{
var lastMatch = context.Transitions.Last.Value;
if (lastMatch.Transition.IsMatch)
result.UnionWith(lastMatch.Transition.MatchSet);
}
}
long nfaUpdateTime = updateTimer.ElapsedMilliseconds;
return result;
}
示例8: CheckHitCollector
/// <summary>
/// Tests that a query matches the an expected set of documents using a
/// HitCollector.
///
/// <p>
/// Note that when using the HitCollector API, documents will be collected
/// if they "match" regardless of what their score is.
/// </p> </summary>
/// <param name="query"> the query to test </param>
/// <param name="searcher"> the searcher to test the query against </param>
/// <param name="defaultFieldName"> used for displaying the query in assertion messages </param>
/// <param name="results"> a list of documentIds that must match the query </param>
/// <seealso cref= #checkHits </seealso>
public static void CheckHitCollector(Random random, Query query, string defaultFieldName, IndexSearcher searcher, int[] results)
{
QueryUtils.Check(random, query, searcher);
Trace.TraceInformation("Checked");
SortedSet<int?> correct = new SortedSet<int?>();
for (int i = 0; i < results.Length; i++)
{
correct.Add(Convert.ToInt32(results[i]));
}
SortedSet<int?> actual = new SortedSet<int?>();
Collector c = new SetCollector(actual);
searcher.Search(query, c);
Assert.AreEqual(correct, actual, "Simple: " + query.ToString(defaultFieldName));
for (int i = -1; i < 2; i++)
{
actual.Clear();
IndexSearcher s = QueryUtils.WrapUnderlyingReader(random, searcher, i);
s.Search(query, c);
Assert.AreEqual(correct, actual, "Wrap Reader " + i + ": " + query.ToString(defaultFieldName));
}
}
示例9: BuildWall
private static void BuildWall(int X, int Y)
{
const char IgnoreAbove = '÷';
byte A, B, L, R, N;
char C;
SortedSet<char> Ch = new SortedSet<char>();
SortedSet<char> ChLeft = new SortedSet<char>();
{
C = (char)Buffers.WorldMap[X, Y];
switch((char)C)
{
case 'A':
case 'B':
{
AB = C;
Ch.Add(C);
for(int m = 1; m <= 13; m++)
Ch.Add((char)m);
if (LastAB != C )
{
ChLeft = Ch;
ChLeft.Remove((char)3);
ChLeft.Remove((char)6);
ChLeft.Remove((char)9);
}
else
ChLeft = Ch;
N = 0;
break;
}
case 'C':
case 'D':
{
CD = C;
Ch.Clear();
Ch.Add((char)C);
for(int m = 1; m <= 26; m++)
Ch.Add((char)m);
Ch.Add('A');
Ch.Add('B');
Ch.Add(IgnoreAbove);
ChLeft = Ch;
N = 13;
break;
}
default:
return;
}
SortedSet<char> temp = new SortedSet<char>();
temp = Ch;
temp.Remove(IgnoreAbove);
A = System.Convert.ToByte(1 - System.Convert.ToByte(((temp.Contains((char)Buffers.WorldMap[X, Y])) || (Y == 0))));
B = System.Convert.ToByte(2 * System.Convert.ToByte(!(Y == Buffers.NV - 1) || Ch.Contains((char)(Buffers.WorldMap[X, Y + 1]))));
L = System.Convert.ToByte(4 * System.Convert.ToByte(! ((X == 0) || ChLeft.Contains((char)Buffers.WorldMap[X - 1, Y]))));
R = System.Convert.ToByte(8 * System.Convert.ToByte(!((X == Buffers.Options.XSize - 1) || Ch.Contains((char)Buffers.WorldMap[X + 1, Y]))));
switch((A + B + L + R))
{
case 0:
{
if ((X > 0) && (Y > 0) )
if( ( !(Ch.Contains((char)Buffers.WorldMap[X - 1, Y - 1]))) )
{ Buffers.WorldMap[X, Y] = (char)(10 + N); return; }
if ((X < Buffers.Options.XSize - 1) && (Y > 0) )
if( !(Ch.Contains((char)Buffers.WorldMap[X + 1, Y - 1])) )
{ Buffers.WorldMap[X, Y] = (char)(11 + N); return; }
if ((X > 0) && (Y < Buffers.NV - 1) )
if ( !(Ch.Contains((char)Buffers.WorldMap[X - 1, Y + 1])) )
{ Buffers.WorldMap[X, Y] = (char)(12 + N); return; }
if ((X < Buffers.Options.XSize - 1) && (Y < Buffers.NV - 1) )
if ( !(Ch.Contains((char)Buffers.WorldMap[X + 1, Y + 1])) )
{ Buffers.WorldMap[X, Y] = (char)(13 + N); return; }
Buffers.WorldMap[X, Y] = (char)(5 + N);
break;
}
case 1:
Buffers.WorldMap[X, Y] = (char)(2 + N);
break;
case 2:
Buffers.WorldMap[X, Y] = (char)(8 + N);
break;
case 4:
Buffers.WorldMap[X, Y] = (char)(4 + N);
break;
case 8:
Buffers.WorldMap[X, Y] = (char)(6 + N);
break;
case 5:
Buffers.WorldMap[X, Y] = (char)(1 + N);
break;
case 6:
Buffers.WorldMap[X, Y] = (char)(7 + N);
break;
case 9:
Buffers.WorldMap[X, Y] = (char)(3 + N);
break;
case 10:
Buffers.WorldMap[X, Y] = (char)(9 + N);
break;
default:
Buffers.WorldMap[X, Y] = (char)(5 + N);
//.........这里部分代码省略.........
示例10: Main
static void Main()
{
List<string> input = new List<string>();
do
{
input.Add(Console.ReadLine());
} while (input[input.Count - 1] != "END");
input.RemoveAt(input.Count - 1);
SortedSet<string> setVenues = new SortedSet<string>();
SortedSet<string> setPerformers = new SortedSet<string>();
HashSet<string> results = new HashSet<string>();
for (int i = 0; i < input.Count; i++)
{
for (int j = 0; j < input.Count; j++)
{
if (input[i].Split(';')[0] == input[j].Split(';')[0])
{
if (input[i].Split(';')[1] == input[j].Split(';')[1])
{
setPerformers.Add(input[j].Split(';')[2]);
}
}
}
results.Add(input[i].Split(';')[0] + ":" + input[i].Split(';')[1] + ":" + string.Join((", "), setPerformers));
setPerformers.Clear();
}
List<string> resultsList = new List<string>();
resultsList.AddRange(results);
List<string> actualResults = new List<string>();
for (int i = 0; i < resultsList.Count; i++)
{
for (int j = 0; j < resultsList.Count; j++)
{
if (resultsList[i].Split(':')[0] == resultsList[j].Split(':')[0])
{
setVenues.Add(resultsList[j]);
if (i != j)
{
resultsList.RemoveAt(j);
j--;
}
}
}
resultsList.InsertRange(i, setVenues);
i += setVenues.Count;
setVenues.Clear();
}
results.Clear();
for (int i = 0; i < resultsList.Count; i++)
{
results.Add(resultsList[i]);
}
resultsList.Clear();
resultsList.AddRange(results);
for (int i = 0; i < resultsList.Count; i++)
{
if (i == 0)
{
Console.WriteLine("{0}\n->{1}: {2}", resultsList[i].Split(':')[0], resultsList[i].Split(':')[1], resultsList[i].Split(':')[2]);
}
else
{
if (resultsList[i].Split(':')[0] == resultsList[i - 1].Split(':')[0])
{
Console.WriteLine("->{0}: {1}", resultsList[i].Split(':')[1], resultsList[i].Split(':')[2]);
}
else
{
Console.WriteLine("{0}\n->{1}: {2}", resultsList[i].Split(':')[0], resultsList[i].Split(':')[1], resultsList[i].Split(':')[2]);
}
}
}
}
示例11: GetPathUsingAStar
private IEnumerable<Tile> GetPathUsingAStar(IEvacuateable person, BuildingBlock destination)
{
bool firstRun = true;
SortedSet<BuildingBlock> priorityQueue = new SortedSet<BuildingBlock>(Comparer<BuildingBlock>.Default);
Dictionary<string, BuildingBlock> closedSet = new Dictionary<string, BuildingBlock>();
List<BuildingBlock> unvisitedVertices = TheFloorPlan.Tiles.Values.Cast<BuildingBlock>().ToList();
foreach (BuildingBlock point in unvisitedVertices)
{
point.LengthToDestination = point.DiagonalDistanceTo(destination);
point.Parent = null;
if (firstRun)
firstRun = false;
else
point.LengthFromSource = 100000;
point.IsChecked = false;
}
unvisitedVertices.Remove(person.Position as BuildingBlock);
BuildingBlock currentPosition = person.Position as BuildingBlock;
if (currentPosition == null) return null;
currentPosition.LengthFromSource = 0;
unvisitedVertices.Insert(0, currentPosition);
while (!Equals(currentPosition, destination))
{
foreach (BuildingBlock buildingBlock in currentPosition.BuildingBlockNeighbours)
{
if (buildingBlock.IsChecked == false)
{
if (!closedSet.ContainsKey(Settings.Coordinate(buildingBlock.X, buildingBlock.Y, buildingBlock.Z)))
{
priorityQueue.Add(buildingBlock);
}
}
}
CheckNeighbors(currentPosition, priorityQueue);
if (priorityQueue.Count == 0)
{
if (closedSet.ContainsKey(Settings.Coordinate(currentPosition.X, currentPosition.Y, currentPosition.Z)) == false)
closedSet.Add(Settings.Coordinate(currentPosition.X, currentPosition.Y, currentPosition.Z), currentPosition);
foreach (BuildingBlock buildingBlock in unvisitedVertices)
{
buildingBlock.IsChecked = false;
}
continue;
}
currentPosition.IsChecked = true;
currentPosition = priorityQueue.First();
priorityQueue.Clear();
}
List<BuildingBlock> path = new List<BuildingBlock>();
BuildingBlock parent = destination;
do
{
path.Add(parent);
parent = parent.Parent;
} while (parent != null);
path.Reverse();
return path;
}
示例12: _dirUrlIndex
__tuple<int, int> _dirUrlIndex(string nUrl)
{
int pos_ = nUrl.IndexOf(@"\");
if (pos_ < 0)
{
return null;
}
string url_ = nUrl.Substring(pos_ + 1);
int pos0_ = url_.IndexOf(@"/");
int pos1_ = url_.IndexOf(@"\");
int pos2_ = url_.IndexOf(@"*");
int pos3_ = url_.IndexOf(@":");
SortedSet<int> sortedSet_ = new SortedSet<int>();
sortedSet_.Add(pos0_);
sortedSet_.Add(pos1_);
sortedSet_.Add(pos2_);
sortedSet_.Add(pos3_);
int start_ = -1;
foreach (int i in sortedSet_)
{
if (i > 0)
{
start_ = i;
break;
}
}
if (start_ < 0)
{
return null;
}
url_ = url_.Substring(start_);
pos2_ = url_.LastIndexOf(@"*");
pos3_ = url_.LastIndexOf(@":");
sortedSet_.Clear();
sortedSet_.Add(pos2_);
sortedSet_.Add(pos3_);
int pos4_ = -1;
foreach (int i in sortedSet_)
{
if (i > 0)
{
pos4_ = i;
break;
}
}
int pos5_ = -1;
pos0_ = url_.LastIndexOf(@"/");
pos1_ = url_.LastIndexOf(@"\");
if (pos0_ < 0 && pos1_ < 0)
{
return null;
}
if (pos1_ < pos0_)
{
pos5_ = pos4_;
}
else
{
pos5_ = pos1_;
}
if (pos5_ < 0)
{
return new __tuple<int, int>(start_ + pos_ + 1, pos5_);
}
else
{
return new __tuple<int, int>(start_ + pos_ + 1, pos5_ + start_ + pos_ + 1);
}
}
示例13: RemoveRedundantMethods
// Remove overridden methods, methods that differ by const/non-const return values
// and abstract class constructors
void RemoveRedundantMethods()
{
// Remove by index, not by reference, otherwise the wrong method could be removed.
// MethodDefinition.Equals compares methods from the POV of C#, not C++,
// so const/non-const methods will be equal.
var removedMethodsIndices = new SortedSet<int>();
foreach (var @class in Project.ClassDefinitions.Values)
{
for (int i = 0; i < @class.Methods.Count; i++)
{
var method = @class.Methods[i];
if (method.IsConstructor)
{
if (@class.IsAbstract) removedMethodsIndices.Add(i);
continue;
}
// Check if the method already exists in a base class
var baseClass = @class.BaseClass;
while (baseClass != null)
{
var baseMethod = baseClass.Methods.FirstOrDefault(m => m.Equals(method));
if (baseMethod != null)
{
if (baseMethod.IsExcluded)
{
method.IsExcluded = true;
}
else
{
removedMethodsIndices.Add(i);
}
break;
}
baseClass = baseClass.BaseClass;
}
for (int j = i + 1; j < @class.Methods.Count; j++)
{
var method2 = @class.Methods[j];
if (!method.Equals(method2)) continue;
var type1 = method.ReturnType;
var type2 = method2.ReturnType;
bool const1 = type1.IsConst || (type1.Referenced != null && type1.Referenced.IsConst);
bool const2 = type2.IsConst || (type2.Referenced != null && type2.Referenced.IsConst);
// Prefer non-const return value
if (const1)
{
if (!const2)
{
removedMethodsIndices.Add(i);
break;
}
}
else if (const2)
{
removedMethodsIndices.Add(j);
break;
}
// Couldn't see the difference
//throw new NotImplementedException();
}
}
foreach (int i in removedMethodsIndices.Reverse())
{
@class.Methods.RemoveAt(i);
}
removedMethodsIndices.Clear();
}
}
示例14: OnProcess
protected override void OnProcess(PixelRegion sourcePixelRegion, PixelRegion targetPixelRegion)
{
SortedSet<uint> array = new SortedSet<uint>();
//int width = Convert.ToInt32(sourcePixelRegion.ImageSize.Width);
targetPixelRegion.ForEachRow((index, width, position) =>
{
for (int i = 0; i < width; i++)
{
var pixel = index + i;
array.Clear();
//var pixel = Convert.ToInt32(index + position.X + i);
var pixelCentral = GetPixelOrDefault(sourcePixelRegion.ImagePixels, pixel, 0);
array.Add(GetPixelOrDefault(sourcePixelRegion.ImagePixels, pixel - width - 1, pixelCentral));
array.Add(GetPixelOrDefault(sourcePixelRegion.ImagePixels, pixel - width, pixelCentral));
array.Add(GetPixelOrDefault(sourcePixelRegion.ImagePixels, pixel - width + 1, pixelCentral));
array.Add(GetPixelOrDefault(sourcePixelRegion.ImagePixels, pixel - 1, pixelCentral));
array.Add(pixelCentral);
array.Add(GetPixelOrDefault(sourcePixelRegion.ImagePixels, pixel + 1, pixelCentral));
array.Add(GetPixelOrDefault(sourcePixelRegion.ImagePixels, pixel + width - 1, pixelCentral));
array.Add(GetPixelOrDefault(sourcePixelRegion.ImagePixels, pixel + width, pixelCentral));
array.Add(GetPixelOrDefault(sourcePixelRegion.ImagePixels, pixel + width + 1, pixelCentral));
targetPixelRegion.ImagePixels[pixel] = array.ElementAt((array.Count- 1) /2);//.OrderBy(it => it).ToList()[4];
}
});
//for (; pixel<sourcePixelRegion.ImagePixels.Length-width-2; pixel++)
//{
//for (int i=0; i< targetPixelRegion.ImagePixels.Length-1; i++)
//{
// //targetPixelRegion.ImagePixels[i];
// //targetPixelRegion.ForEachRow((index, width, position) =>
// //{
// // //Parallel.For(0, width, (i) =>
// // for (int i = 0; i < width; i++)
// // {
// //array.Clear();
// ////var pixel = index + i;
// //array.Add(sourcePixelRegion.ImagePixels[pixel - width - 1]);
// //array.Add(sourcePixelRegion.ImagePixels[ pixel - width]);
// //array.Add(sourcePixelRegion.ImagePixels[ pixel - width + 1]);
// //array.Add(sourcePixelRegion.ImagePixels[ pixel - 1]);
// //array.Add(sourcePixelRegion.ImagePixels[ pixel]);
// //array.Add(sourcePixelRegion.ImagePixels[ pixel + 1]);
// //array.Add(sourcePixelRegion.ImagePixels[ pixel + width - 1]);
// //array.Add(sourcePixelRegion.ImagePixels[ pixel + width]);
// //array.Add(sourcePixelRegion.ImagePixels[pixel + width + 1]);
// targetPixelRegion.ImagePixels[pixel] = sourcePixelRegion.ImagePixels[pixel - 1];// GetPixelOrDefault(sourcePixelRegion, pixel);// array[4];
// }// });
//for (int i = 0; i < width; ++i)
//{
// //Almacenamos los pixels alrededor del actual en un array ordenado para coger la mediana
// //var c = sourcePixelRegion.ImagePixels[index + i];
// List<uint> array = new List<uint>();
// var pixel = index + i;
// array.Add(GetPixelOrDefault(sourcePixelRegion, pixel - width - 1));
// array.Add(GetPixelOrDefault(sourcePixelRegion, pixel - width));
// array.Add(GetPixelOrDefault(sourcePixelRegion, pixel - width + 1));
// array.Add(GetPixelOrDefault(sourcePixelRegion, pixel - 1));
// array.Add(GetPixelOrDefault(sourcePixelRegion, pixel));
// array.Add(GetPixelOrDefault(sourcePixelRegion, pixel + 1));
// array.Add(GetPixelOrDefault(sourcePixelRegion, pixel + width - 1));
// array.Add(GetPixelOrDefault(sourcePixelRegion, pixel + width));
// array.Add(GetPixelOrDefault(sourcePixelRegion, pixel + width + 1));
// targetPixelRegion.ImagePixels[pixel] = array.OrderBy(it=>it).ToList()[4];
//}
//});
}
示例15: getTables
SortedSet<Table> getTables()
{
Console.WriteLine ("getTables()");
SortedSet<Table> returnTables = new SortedSet<Table> ();
const string FetchTable = "SELECT * FROM {0}";
if (returnTables.Count != 0) {
Console.WriteLine ("deleting data from provious operations.");
returnTables.Clear ();
}
using (IDbConnection conn_tables = new SqlConnection (connectionString)) {
conn_tables.Open ();
using (IDbCommand comm_tables = conn_tables.CreateCommand ()) {
string ListTablesQuery = string.Format (FetchTable, "sys.tables");
comm_tables.CommandText = ListTablesQuery;
using (IDataReader reader_tables = comm_tables.ExecuteReader ()) {
int NameFieldOrdinal_tables = reader_tables.GetOrdinal ("name");
int IdFieldOrdinal_tables = reader_tables.GetOrdinal ("object_id");
while (reader_tables.Read ()) {
int TableID = reader_tables.GetInt32 (IdFieldOrdinal_tables);
string TableName = reader_tables.GetString (NameFieldOrdinal_tables);
Table table = new Table (Guid.NewGuid (), TableName, TableID);
Console.WriteLine ("table name: {0}", TableName);
returnTables.Add (table);
tables.Add (table.SqlTableID, table);
psc.AddTable (table);
}
}
}
return returnTables;
}
}