本文整理汇总了C#中System.Collections.Queue.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# Queue.Contains方法的具体用法?C# Queue.Contains怎么用?C# Queue.Contains使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Queue
的用法示例。
在下文中一共展示了Queue.Contains方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
// implementar colas
Queue miCola = new Queue();
// encolar objetos
miCola.Enqueue("esta");
miCola.Enqueue("es");
miCola.Enqueue("una");
miCola.Enqueue("cola");
foreach (string cadena in miCola)
Console.WriteLine(cadena);
Console.WriteLine(miCola.Count);
Console.WriteLine(miCola.Contains("esta"));
Console.WriteLine(miCola.Dequeue());
Console.WriteLine(miCola.Dequeue());
Console.WriteLine(miCola.Count);
foreach (string cadena in miCola)
Console.WriteLine(cadena);
Console.Read();
}
示例2: OnCycle
public void OnCycle()
{
try
{
Queue queue = new Queue();
lock (_cycleItems.SyncRoot)
{
while (_cycleItems.Count > 0)
{
IWiredItem wiredItem = (IWiredItem) _cycleItems.Dequeue();
IWiredCycler item = wiredItem as IWiredCycler;
if (item == null)
continue;
IWiredCycler wiredCycler = item;
if (!wiredCycler.OnCycle())
{
if (!queue.Contains(item))
queue.Enqueue(item);
}
}
}
_cycleItems = queue;
}
catch (Exception e)
{
YupiLogManager.LogException(e, "Registered Wired Handling Exception.", "Yupi.Wired");
}
}
示例3: TestStackQueneCollection
private static void TestStackQueneCollection()
{
Random rand = new Random();
Stopwatch sw = new Stopwatch();
Stack<int> stack = new Stack<int>();
Queue<int> queue = new Queue<int>();
int el;
//Stack
sw.Reset();
Console.Write("Adding to Stack...");
sw.Start();
for (int i = 0; i < 100000; i++)
{
stack.Push(i);
}
sw.Stop();
Console.WriteLine(" Time used: " + sw.ElapsedTicks + " ticks");
sw.Reset();
Console.Write("Search in Stack...");
sw.Start();
for (int i = 0; i < 100000; i++)
{
var index = stack.Contains(50000);
}
sw.Stop();
Console.WriteLine(" Time used: " + sw.ElapsedTicks + " ticks");
sw.Reset();
Console.Write("Removing from Stack...");
sw.Start();
for (int i = 0; i < 100000; i++)
{
el = stack.Pop();
el++;
}
sw.Stop();
Console.WriteLine(" Time used: " + sw.ElapsedTicks + " ticks\n");
sw.Reset();
//Queue
Console.Write("Add to Queue...");
sw.Start();
for (int i = 0; i < 100000; i++)
{
queue.Enqueue(i);
}
sw.Stop();
Console.WriteLine(" Time used: " + sw.ElapsedTicks + " ticks");
sw.Reset();
Console.Write("Search in Queue...");
sw.Start();
for (int i = 0; i < 100000; i++)
{
queue.Contains(50000);
}
sw.Stop();
Console.WriteLine(" Time used: " + sw.ElapsedTicks + " ticks");
sw.Reset();
Console.Write("Removing from Queue...");
sw.Start();
for (int i = 0; i < 100000; i++)
{
el = queue.Dequeue();
el++;
}
sw.Stop();
Console.WriteLine(" Time used: " + sw.ElapsedTicks + " ticks\n");
}
示例4: Main
//.........这里部分代码省略.........
}
if (userInput.Key == ConsoleKey.RightArrow)
{
if (direction != left)
{
direction = right;
}
}
if (userInput.Key == ConsoleKey.UpArrow)
{
if (direction != down)
{
direction = up;
}
}
if (userInput.Key == ConsoleKey.DownArrow)
{
if (direction != up) // ako posokata ne e nagore 4ak togava da se mestim nadolo
{
direction = down;
}
}
}
Position snakeHead = snakeElements.Last(); // tozi method vru6ta posledniq element ot opa6kata
Position nextDirection = directions[direction]; // s tozi red vzimame na kade da se dviji zmiqta kato directions e masiva a direction 0,1,2,3
//novata poziciq na zmiqta
Position snakeNewHead = new Position(snakeHead.row + nextDirection.row, snakeHead.col + nextDirection.col);// purvo e X posle e Y kato za primer vzimame stariq direction na row i go
//Position newHead = snakeElements.Last();// tova ni vru6ta glavata na na6ta zmiq i q zapisva v promenlivata new head
snakeElements.Enqueue(snakeNewHead); // tozi kod slaga nova glava vseki put na novata poziciq
// tova proverqva dali glavata na zmiqta ne e izlezla ot ekrana bukvalno
if (snakeNewHead.row < 0 ||
snakeNewHead.col < 0 ||
snakeNewHead.row >= Console.WindowHeight ||
snakeNewHead.col >= Console.WindowWidth) // row = red
{
Console.SetCursorPosition(0, 0);
Console.WriteLine();
Console.WriteLine("Game over");
Console.WriteLine("Your points are: {0}", (snakeElements.Count - 6) * 100); // tova vru6ta broq elementi na zmiqta
return; // prikliu4va izpulnenieto na teku6tiq method
}
//TOVA E KODA AKO ZMIQTA APNE QBALKATA
if (snakeNewHead.col == food.col && snakeNewHead.row == food.row) // tuka slagame statement koito proverqva dali glavata na zmiqta se zasi4a s tazi na xranata
{
do
{
food = new Position(randomNumberGenerator.Next(0, Console.WindowHeight), // slaga qbalkata na random mesto, no tozi put prosto vzima novi stoinosti za novata qbalka
randomNumberGenerator.Next(0, Console.WindowWidth)); // tuka 6te ni se generira slu4aino 4islo koeto 6te opredelq kade e qbalkata
}
while (snakeElements.Contains(food));
sleepTime -= 5; // da stava s 20 milisekundi po-burza
Random r = new Random();
Console.Beep(r.Next(100, 10000), r.Next(60, 500));
}
else // samo kogato zmiqta ne udrq lqbalkata 6te se maxa edna zvezda ot opajkata
{
snakeElements.Dequeue();
}
// garanciqta 4e 6te imame nova qbalka i zmiq e 4e console clear e predi tqx a ne sled tqx
Console.Clear(); // 4isti konzolata
foreach (Position position in snakeElements) // obxojda vsi4kite elementi i postavqme kursora tam kadeto se namira zmiqta
{
Console.SetCursorPosition(position.col, position.row); // tazi poziciq priema left top kolona
Console.WriteLine('*');
}
lastFoodTime = Environment.TickCount; // broq na milisekundi ot na4aloto na sistemata
// TUka e koda za kazvane na programata da 4aka 8 secundi
if (Environment.TickCount - lastFoodTime >= foodDisappearTime)
{
Console.SetCursorPosition(food.col, food.row); // TAKA MAXAME STARATA QBALKA
Console.WriteLine(" ");
do
{
food = new Position(randomNumberGenerator.Next(0, Console.WindowHeight), // slaga qbalkata na random mesto, no tozi put prosto vzima novi stoinosti za novata qbalka
randomNumberGenerator.Next(0, Console.WindowWidth)); // tuka 6te ni se generira slu4aino 4islo koeto 6te opredelq kade e qbalkata
}
while (snakeElements.Contains(food));
}
Console.SetCursorPosition(food.col, food.row); // S TOZI KOD RISUVAME QBALKATA NA RANDOM MESTO V KONZOLATA
Console.Write('@');
Thread.Sleep(sleepTime); // konzolata spira prosto bavi zmiqta s opredeleno vreme
}
}
示例5: GetDeltaFinal
private void GetDeltaFinal(NFA nfa)
{
Queue newstates = new Queue ();
Queue queue = new Queue ();
Hashtable odelta = nfa.Delta;
Hashtable ndelta = new Hashtable ();
newstates.Enqueue (current_state);
queue.Enqueue (current_state);
while (queue.Count != 0) {
string substate = (string) queue.Dequeue ();
string [] states = substate.Split (':');
foreach (string sym in alph) {
int icount = 0;
string [] nstates = new string [states.Length];
foreach (string sub in states) {
nstates [icount++] = (string) odelta [new Context (sub, sym)];
}
string union = Union (nstates);
if (union == null)
union = "ERROR";
if (!newstates.Contains (union)) {
newstates.Enqueue (union);
queue.Enqueue (union);
}
ndelta.Add (new Context (substate, sym), union);
}
}
this.delta = ndelta;
int qcount = 0;
string [] qstates = new string [newstates.Count];
foreach (object o in newstates)
qstates [qcount++] = (string) o;
this.states = qstates;
string [] ofstates = nfa.FState;
ArrayList list = new ArrayList ();
foreach (string sub in states)
foreach (string asub in ofstates)
if (sub.IndexOf (asub) != -1) {
list.Add (sub);
break;
}
string [] farray = new string [list.Count];
list.CopyTo (farray);
f_states = farray;
}
示例6: ListQualifierDescendants
/// <summary>
/// lists the IDs of all qualifiers that are descendants of the given qualifier ID
/// </summary>
/// <param name="ancestorQualifierID">the ID of the qualifier whose descendants are sought</param>
/// <param name="breadthFirst">if true, descendants are listed in breadth first order, otherwise depth first postorder, which happens to be the correct order for deleting subtrees in which all nodes are singly parented.</param>
/// <returns>an array of Qualifier IDs of all descendant qualifiers</returns>
public static int[] ListQualifierDescendants( int ancestorQualifierID, bool breadthFirst )
{
ArrayList descendantList = new ArrayList();
//use a breadth first order approach
//this code is still not optimized, i.e. we are searching the WHOLE hierarchy table even after
//we have traversed it once. - Karim's notes
if(breadthFirst)
{
Queue descendantQueue = new Queue();
int[] children = ListQualifierChildren(ancestorQualifierID);
foreach (int child in children)
{
descendantList.Add(child);
descendantQueue.Enqueue(child);
}
while( descendantQueue.Count > 0 )
{
int[] moreDescendants = ListQualifierChildren(Convert.ToInt32(descendantQueue.Dequeue()));
foreach(int grandchild in moreDescendants)
{
if(!descendantQueue.Contains(grandchild))
{
descendantList.Add(grandchild);
descendantQueue.Enqueue(grandchild);
}
}
}
}
//use a depth first postorder method instead
else
{
AuthorizationUtilities.QualifierPostOrder(ancestorQualifierID, descendantList);
}
return Utilities.ArrayListToIntArray(descendantList);
}
示例7: OnCycle
public void OnCycle()
{
try
{
Queue queue = new Queue();
lock (_cycleItems.SyncRoot)
{
while (_cycleItems.Count > 0)
{
IWiredItem wiredItem = (IWiredItem) _cycleItems.Dequeue();
IWiredCycler item = wiredItem as IWiredCycler;
if (item == null)
continue;
IWiredCycler wiredCycler = item;
if (!wiredCycler.OnCycle())
if (!queue.Contains(item))
queue.Enqueue(item);
}
}
_cycleItems = queue;
}
catch (Exception e)
{
ServerLogManager.LogException(e, MethodBase.GetCurrentMethod());
}
}
示例8: AddGenericSpecializedMethod
/// <summary>
/// </summary>
/// <param name="method">
/// </param>
/// <param name="stackCall">
/// </param>
private void AddGenericSpecializedMethod(IMethod method, Queue<IMethod> stackCall)
{
if (this.usedGenericSpecialiazedMethods == null || method == null)
{
return;
}
if (!method.IsGenericMethod)
{
if (method.DeclaringType.IsGenericType && !stackCall.Contains(method))
{
this.DiscoverRequiredTypesAndMethodsInMethod(method, stackCall);
}
return;
}
if (this.usedGenericSpecialiazedMethods.Contains(method))
{
return;
}
this.usedGenericSpecialiazedMethods.Add(method);
this.DiscoverRequiredTypesAndMethodsInMethod(method, stackCall);
}
示例9: DumpMenus
private static void DumpMenus(string fileName)
{
if (File.Exists(fileName))
{
LoadFuncNames(firmConsts.DFR_file);
BinaryReader br = null;
byte[] data;
using (br = new BinaryReader(File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
{
data = br.ReadBytes((int)br.BaseStream.Length);
}
Queue<long> q = new Queue<long>();
List<long> resolved = new List<long>();
menus = new Dictionary<long, Struct6>();
elements = new Dictionary<long, Struct14>();
resolved.Add(0);
uint addrOffset = firmConsts.Copy_Offset;
foreach (var l in firmConsts.MenuRootList)
{
q.Enqueue(l);
}
while (q.Count > 0)
{
var addr = q.Dequeue();
var ss1 = string.Format("Addr 0x{0:X8}", addr);
var s6 = new Struct6(data, addr, addrOffset);
s6.ReadElements(data);
resolved.Add(addr);
menus.Add(addr, s6);
foreach (var s14 in s6.menu_elements)
{
if (Array.IndexOf(firmConsts.MenuRootList, s14.menu_ptr) != -1)
{
}
if (resolved.Contains(s14.menu_ptr) == false &&
q.Contains(s14.menu_ptr) == false)
{
if (s14.menu_ptr < firmConsts.Copy_To)
{
int az = 0;
}
var ss2 = string.Format("Menu 0x{0:X8} MenuEl 0x{1:X8} SubMenu 0x{2:X8}", addr, s14.mem_loc, s14.menu_ptr);
q.Enqueue(s14.menu_ptr);
}
}
}
using (var sw = new StreamWriter(File.Open(fileName + ".menu.txt", FileMode.Create, FileAccess.Write, FileShare.ReadWrite)))
{
using (var sw2 = new StreamWriter(File.Open(fileName + ".menu_sym.idc", FileMode.Create, FileAccess.Write, FileShare.ReadWrite)))
{
sw2.WriteLine("#include <idc.idc>");
sw2.WriteLine("static MakeMenu(ref, txt, type) {");
sw2.WriteLine("\tMakeNameEx(ref, txt, 0 );");
sw2.WriteLine("\tif( type == 0) {");
sw2.WriteLine("\t\tMakeUnknown(ref, 0x20, 0 );");
sw2.WriteLine("\t\tMakeStructEx(ref, 0x20, \"Menu\");");
sw2.WriteLine("\t} else {");
sw2.WriteLine("\t\tMakeUnknown(ref, 0x10, 0 );");
sw2.WriteLine("\t\tMakeStructEx(ref, 0x10, \"MenuEl\");");
sw2.WriteLine("\t}");
sw2.WriteLine("}");
sw2.WriteLine("static main() {");
sw2.WriteLine(" Message(\"Menu Name: Start\\n\");");
foreach (var l in firmConsts.MenuRootList)
{
MenuDump(sw, sw2, "", l);
}
sw2.WriteLine("\tMessage(\"Menu Name: Done\\n\");");
sw2.WriteLine("}");
}
}
}
}
示例10: Astar
public void Astar(string ftablename, string startpoint, string endpoint)
{
#region ʹ���ֵ䷽ʽ
//����ʵ�ַ�ʽ��һ��ʹ���ֶδ洢��ͬ��ֵ������һ��ʹ�ù����Point��ʵ��
//ʹ���ֶη�ʽ���
Queue<int> Open = new Queue<int>();
//Queue<int> Open = new Queue<int>();
Queue<int> Close = new Queue<int>();
//��ǰ���·��ֵ
Hashtable GScore = new Hashtable();
//��ǰ��㵽��ֹ���֮��Ĺ���ֵ
Hashtable HScore = new Hashtable();
//�ܺ�=��ǰ���+����ֵ
Hashtable FScore = new Hashtable();
//���ﵱǰ����ǰһ�����·���ϵĽ��
Hashtable ComeFrom = new Hashtable();
string sqlstr, tablename, tmpAdjVertex;
DataTable VertexTable;
int totalVertex, start, end, curVertex, adjVertex,tmpVertexId;
string tmpVertex;
string[] adjVertexes;
tablename = GetLayerName(ftablename) + "_vertex_adjaction";
sqlstr = "select vertex_id,vertex_adj_id,line_adj_id from " + tablename + " " + "order by vertex_id asc";
VertexTable = postDB.DoQueryEx(sqlstr);
totalVertex = VertexTable.Rows.Count;
////��ʼ��
start = int.Parse(startpoint);
end = int.Parse(endpoint);
//��ʼ�����뵽open������
Open.Enqueue(start);
curVertex = start;
for (int i = 0; i < totalVertex;i++ )
{
tmpVertex = VertexTable.Rows[i]["vertex_id"].ToString();
tmpVertexId = Convert.ToInt32(tmpVertex);
GScore.Add(tmpVertexId, MaxDistance);
HScore.Add(tmpVertexId, 0.0);
FScore.Add(tmpVertexId, MaxDistance);
}
GScore[curVertex] = (double)0.0;
HScore[curVertex] = (double)GetHeuristic(curVertex, end, ftablename);
FScore[curVertex] = (double)HScore[curVertex];
while (Open.Count > 0)
{
//��open����ȡ��FScore��С�Ľ��
//open������ֻ�洢�н����
curVertex = GetMinTotalCostVertex(Open, FScore);
if (curVertex.Equals(end))
{
//�������������·��д������
ConstructPath(ComeFrom,start,end,ftablename);
return;
}
//��open������ɾ����Сֵ��Ӧ�Ľ�㣬����dequeue����
Open=RemoveMinFromOpen(Open, curVertex);
Close.Enqueue(curVertex);
tmpAdjVertex = VertexTable.Rows[curVertex - 1]["vertex_adj_id"].ToString();
adjVertexes = tmpAdjVertex.Split('_');
bool newIsBetter = false;
double tentativeGScore;
for (int i = 0; i < adjVertexes.Length; i++)
{
adjVertex = int.Parse(adjVertexes[i]);
//��������close���У��������ٽ��в�����������һ��
if (! Close.Contains(adjVertex))
{
tentativeGScore = (double)GScore[curVertex] + GetDistance(curVertex, adjVertex, ftablename);
//�������open������
if (!Open.Contains(adjVertex))
{
Open.Enqueue(adjVertex);
newIsBetter = true;
}
else if (tentativeGScore < (double) GScore[adjVertex])
{
newIsBetter = true;
}
if (newIsBetter)
{
ComeFrom[adjVertex] = curVertex;
GScore[adjVertex] = tentativeGScore;
HScore[adjVertex] = GetHeuristic(adjVertex, end, ftablename);
FScore[adjVertex] = (double)GScore[adjVertex] + (double) HScore[adjVertex];
}
}
}
}
//�����õ�comefromΪ�գ���δ�ҵ���Ӧ��·��
//����������δ�õ����˵��δ�ҵ���ص�·��
#endregion
}
示例11: DikkstraImpl
public void DikkstraImpl(GraphImpl g, int start_vertex, int dest_vertex)
{
Queue<int> visited_vertices = new Queue<int>(g.GetTotalNodes());
int[] distance_list = new Int32[g.GetTotalNodes()];
List<int> current_list = new List<int>(g.GetTotalNodes());
int[] shortest_vertices = new Int32[g.GetTotalNodes()];
for (int z = 0; z < g.GetTotalNodes(); z++)
{
distance_list[z] = Int32.MaxValue;
}
distance_list[start_vertex] = 0;
current_list.Add(start_vertex);
Node start_node = g.searchNode(start_vertex);
while (current_list.Count != 0)
{
List<int> pseudo_priority_list = new List<int>(current_list.Count);
foreach (int value in current_list)
{
int xxx = distance_list[value];
pseudo_priority_list.Add(xxx);
}
int small = pseudo_priority_list.Min();
int index = pseudo_priority_list.IndexOf(small);
int current_vertex = current_list[index];
Node current_node = g.searchNode(current_vertex);
List<Edge> edge_list = new List<Edge>();
edge_list = current_node.GetEdgeList();
for (int z = 0; z < edge_list.Count; z++)
{
int r = edge_list[z]._dest.node_id;
if (!visited_vertices.Contains(r) && !current_list.Contains(r))
{
current_list.Add(r);
}
int edge1 = g.Edge_cost(start_node, current_vertex);
if (edge1 == -1)
{
edge1 = distance_list[current_vertex];
}
if (edge1 > distance_list[current_vertex])
{
edge1 = distance_list[current_vertex];
}
int edge2 = g.Edge_cost(current_node, r);
if (distance_list[r] > (edge1 + edge2))
{
shortest_vertices[r] = r;
shortest_vertices[r] = current_vertex;
distance_list[r] = edge1 + edge2;
}
}
visited_vertices.Enqueue(current_vertex);
current_list.Remove(current_vertex);
}
for (int z = 0; z < g.GetTotalNodes(); z++)
{
Console.WriteLine("shortest cost to reach " + z + " from " + start_vertex + " -> " + distance_list[z]);
}
ReturnCostForSpecificPath(g, start_vertex, dest_vertex, distance_list, shortest_vertices);
}
示例12: Main
static void Main(string[] args)
{
byte right = 0; //massive index
byte left = 1;
byte down = 2;
byte up = 3;
Position[] directions = new Position[]
{
new Position(0, 1), // right
new Position(0, -1), // left
new Position(1, 0), // down
new Position(-1, 0) // up
};
int sleepTime = 100;
int direction = right;
Random randomNumberGenerator = new Random();
Console.BufferHeight = Console.WindowHeight;
Position food = new Position(randomNumberGenerator.Next(0, Console.WindowHeight), //food
randomNumberGenerator.Next(0, Console.WindowWidth));
Queue<Position> snakeElements = new Queue<Position>();
for (int i = 0; i <= 5; i++)
{
snakeElements.Enqueue(new Position(0, i));
}
foreach (Position position in snakeElements)
{
Console.SetCursorPosition(position.cow, position.row);
Console.Write("*");
}
while (true)
{
Position snakeHead = snakeElements.Last();
Position nextDirection = directions[direction];
Position snakeNewHead = new Position(snakeHead.row + nextDirection.row,
snakeHead.cow + nextDirection.cow);
if (snakeNewHead.row < 0 || snakeNewHead.cow < 0 || snakeNewHead.row >= Console.WindowHeight
|| snakeNewHead.cow >= Console.WindowWidth || snakeElements.Contains(snakeNewHead))
{
Console.SetCursorPosition(0, 0);
Console.BackgroundColor = ConsoleColor.DarkRed;
Console.Beep();
Console.Beep();
Console.Beep();
Console.WriteLine("Game Over !!!");
Console.WriteLine("Your points are: {0}", snakeElements.Count - 6);
return;
}
if (snakeNewHead.cow == food.cow && snakeNewHead.row == food.row)
{
// feeding the snake
food = new Position(randomNumberGenerator.Next(0, Console.WindowHeight),
randomNumberGenerator.Next(0, Console.WindowWidth));
Console.Beep();
sleepTime--; // speed up
}
else
{
// moving...
snakeElements.Dequeue();
}
if (Console.KeyAvailable)
{
ConsoleKeyInfo userInput = Console.ReadKey();
if (userInput.Key == ConsoleKey.LeftArrow)
{
if (direction != right) direction = left;
}
if (userInput.Key == ConsoleKey.RightArrow)
{
if (direction != left) direction = right;
}
if (userInput.Key == ConsoleKey.UpArrow)
{
if (direction != down) direction = up;
}
if (userInput.Key == ConsoleKey.DownArrow)
{
if(direction != up) direction = down;
}
}
snakeElements.Enqueue(snakeNewHead);
Console.Clear();
foreach (Position position in snakeElements)
{
Console.SetCursorPosition(position.cow, position.row);
Console.Write("*");
}
Console.SetCursorPosition(food.cow, food.row);
Console.Write("@");
//.........这里部分代码省略.........
示例13: CheckFileList
// Checks download file list
private IEnumerator CheckFileList (List<DownloadFileInfo> list)
{
List<DownloadFileInfo> tmp_list = new List<DownloadFileInfo>(list);
List<string> verify_file_list = new List<string>();
List<string> remove_list = new List<string>();
Queue<int> rnd_list = new Queue<int>();
bool verify_success = true;
int rnd_index = -1;
DateTime cached_time = File.GetLastWriteTime(target_path_ + kCachedFileName);
check_time_ = DateTime.Now;
delete_file_list_.Clear();
// Randomly check list
if (cached_list_.Count > 0)
{
int max_count = cached_list_.Count;
int count = Math.Min(Math.Max(1, max_count / 10), 10);
System.Random rnd = new System.Random((int)DateTime.Now.Ticks);
while (rnd_list.Count < count)
{
rnd_index = rnd.Next(1, max_count + 1) - 1;
if (!rnd_list.Contains(rnd_index))
rnd_list.Enqueue(rnd_index);
}
DebugUtils.DebugLog("Random check file count is {0}", rnd_list.Count);
rnd_index = rnd_list.Count > 0 ? rnd_list.Dequeue() : -1;
}
// Checks local files
int index = 0;
foreach (DownloadFileInfo file in cached_list_)
{
DownloadFileInfo item = list.Find(i => i.path == file.path);
if (item != null)
{
string path = target_path_ + file.path;
FileInfo info = new FileInfo(path);
if (!File.Exists(path) || item.size != info.Length || item.hash != file.hash)
{
remove_list.Add(file.path);
}
else
{
string filename = Path.GetFileName(item.path);
if (filename[0] == '_' || index == rnd_index ||
File.GetLastWriteTime(path).Ticks > cached_time.Ticks)
{
if (index == rnd_index) {
rnd_index = rnd_list.Count > 0 ? rnd_list.Dequeue() : -1;
}
verify_file_list.Add(file.path);
MD5Async.Compute(ref path, ref item, delegate (string p, DownloadFileInfo f, bool is_match)
{
if (VerifyCallback != null)
VerifyCallback(p);
verify_file_list.Remove(f.path);
if (is_match)
{
list.Remove(f);
}
else
{
remove_list.Add(f.path);
verify_success = false;
}
});
}
else
{
list.Remove(item);
}
}
}
else
{
remove_list.Add(file.path);
}
++index;
}
while (verify_file_list.Count > 0)
{
yield return new WaitForSeconds(0.1f);
}
RemoveCachedList(remove_list);
DebugUtils.Log("Random validation has {0}", (verify_success ? "succeeded" : "failed"));
//.........这里部分代码省略.........
示例14: BalanceIntakes
private void BalanceIntakes()
{
Queue<Part> intakeQueue = new Queue<Part>( _editor.ship.Parts.Where( x => GetPartType( x ) == PartType.Intake ) // do not treat intakeandengine parts as intake but as engine
.OrderByDescending( x => x.Modules.OfType<ModuleResourceIntake>().First().area ) ); // queue is easier to handle when distributing items to engines - this makes sure we can only handle a part once
Utils.Log( "Intakes found: {0}", string.Join( ", ", intakeQueue.Select( x => x.partInfo.title + ": " + x.Modules.OfType<ModuleResourceIntake>().First().area ).ToArray() ) );
List<WeightedPartList> totalPartList = new List<WeightedPartList>();
// so far all jets have intakeair ratio of 15, so we treat jets, turbos and rapiers alike
// TODO for future: take intakeair ratio into account. how exactly? I donno :)
// handle engines grouped by type, so far its by placement order
foreach ( Part part in _editor.ship.parts )
{
if ( GetPartType( part ) == PartType.AirBreatherEngine )
{
WeightedPartList wpl = new WeightedPartList();
wpl.AddPart( part );
totalPartList.Add( wpl );
}
else if ( GetPartType( part ) == PartType.IntakeAndEngine )
{
WeightedPartList wpl = new WeightedPartList();
wpl.IntakeAreaSum = part.Modules.OfType<ModuleResourceIntake>().First().area; // add intake area of part that has both intake and engine in one
wpl.AddPart( part );
totalPartList.Add( wpl );
}
}
Utils.Log( "Jets found: {0}", string.Join( ", ", totalPartList.Select( x => x.PartList.First().partInfo.title ).ToArray() ) );
if ( intakeQueue.Count > 0 && totalPartList.Count > 0 )
{
// strip ship from intakes and jets
_editor.ship.parts.RemoveAll( x => intakeQueue.Contains( x ) );
Utils.Log( "removed intakes temporarily" );
_editor.ship.parts.RemoveAll( x => totalPartList.Select( y => y.PartList.First() ).Contains( x ) );
Utils.Log( "removed jets temporarily" );
int intakeCount = intakeQueue.Count;
for ( int i = 0; i < intakeCount; i++ )
{
Part part = intakeQueue.Dequeue();
totalPartList.Where( x => x.IntakeAreaSum == totalPartList.Min( y => y.IntakeAreaSum ) ).First().AddPart( part ); // WeightedPartList with the least IntakeAreaSum will get the next intake assigned
}
// go through all part lists, reverse them and add them back to ship
foreach ( WeightedPartList partList in totalPartList )
{
partList.PartList.Reverse();
_editor.ship.parts.AddRange( partList.PartList ); // add parts for engine and its intakes back to ship
Utils.Log( "Intake/engine set: {0}, total intake area: {1}", string.Join( ", ", partList.PartList.Select( x => x.name ).ToArray() ), partList.IntakeAreaSum );
}
Utils.Log( "Finished intakes - jets balance" );
}
else
{
Utils.Log( "There are either no intakes or no engines" );
}
}
示例15: OnCycle
public void OnCycle()
{
try
{
var queue = new Queue();
lock (_cycleItems.SyncRoot)
{
while (_cycleItems.Count > 0)
{
var wiredItem = (IWiredItem) _cycleItems.Dequeue();
var item = wiredItem as IWiredCycler;
if (item == null)
continue;
var wiredCycler = item;
if (!wiredCycler.OnCycle())
if (!queue.Contains(item))
queue.Enqueue(item);
}
}
_cycleItems = queue;
}
catch (Exception e)
{
Writer.Writer.HandleException(e, "WiredHandler.cs:OnCycle");
}
}