queue

Removing top of PriorityQueue?

走远了吗. 提交于 2019-12-06 03:37:18
问题 Assume that I am using the PriorityQueue class from Java.util. I want to remove the largest number from the PriorityQueue pq, which we assume is at the head of the queue. Will the following work? // 1 int head = pq.peek(); pq.dequeue(head); // 2 int head = pq.dequeue(pq.peek()); Would this work the same for non-primitives as well? 回答1: Queue#peek and Queue#element return the head value of the queue, Queue#poll and Queue#remove return and remove it. It looks like int head = pq.poll(); is what

deadlock because of blocking Queue.get() method

China☆狼群 提交于 2019-12-06 03:32:50
As the title implies I have a deadlock and no idea why. I have multiple producers and only one consumer. The schedule_task method will get called by multiple processes after the thread has called the get method of the queue from logging import getLogger from time import sleep from threading import Event, Thread from multiprocessing import Process from Queue import Queue class TaskExecutor(object): def __init__(self): print("init taskExecutor") self.event = Event() self.taskInfos = Queue() task_thread = Thread(target=self._run_worker_thread) self._instantEnd = False self._running = True task

Different Methods of Performing FloodFill

為{幸葍}努か 提交于 2019-12-06 03:23:37
问题 OK everyone I have several different methods of performing a FloodFill. All of them cause problems. I will list the 3 methods and explain what happens with each one. If anyone could give me some pointers that would be great. I have seen some similar posts but none of them have been for C#, java, or VB.net (the only languages I know). The givens for this are that I have a class called PixelData which stores a Color in a CellColor member variable. I have an array that is 50x50 of PixelData

Job queue in node.js

偶尔善良 提交于 2019-12-06 03:00:09
问题 I'm looking for a job queue manager in node.js which can be invoked by php. This is for a web application which needs to send emails, create pdf files and so on which I'd like to perform asynchronous of the php process. Example of the process: User requests a php page Php invokes the job queue manager and adds a task Task is executed in node.js asynchronously of php, preferably when it's a bit more quiet Task is to execute a php script Why this "complex" system? We write all our web

find a pair in a STL list where only first element is known

橙三吉。 提交于 2019-12-06 02:32:20
assumend I have a (filled) list std::list<std::pair<int,otherobject>> myList; and want to find() the first element within this list, where int has a specific value - how can I do that? To explain it a bit further: I want to append these pairs to the list with an int that identifies otherobject but is not unique. The order where these int/otherobject pairs arrive has to be kept. When an int is found during access to elements of this list the first occurence of that int has to be given back (and removed). Thanks! I think I'd use the standard find_if algorithm: auto pos = std::find_if(myList

Queue implementation with circular arrays: Which is the best way to resize a circular array?

时光怂恿深爱的人放手 提交于 2019-12-06 01:57:50
I'm implementing a queue using a circular array , and I'm kind of stuck in the resize() method implementation (when the array is full). Inside the enqueue() method I check if the size of the array equals it's length, and get if it's full. Now, instead of throwing an exception, I'm trying to resize the array. The thing is, I have two cases to consider front <= rear rear < front Which is the best way to copy the elements of the old array into the new, larger one? I thought it using a for-loop, like: newArray = new Array[oldArray.length*2]; if (front <= rear) { for (int i = front; i < rear; i++)

Python threading.Thread can be stopped only with private method self.__Thread_stop()

拈花ヽ惹草 提交于 2019-12-06 01:47:41
问题 I have a function that accepts a large array of x,y pairs as an input which does some elaborate curve fitting using numpy and scipy and then returns a single value. To try and speed things up I am trying to have two threads that I feed the data to using Queue.Queue . Once the data is done. I am trying to have the threads terminate and then end the calling process and return control to the shell. I am trying to understand why I have to resort to a private method in threading.Thread to stop my

Shuffling the training dataset with Tensorflow object detection api

☆樱花仙子☆ 提交于 2019-12-06 01:38:13
I'm working on a logo detection algorithm using the Faster-RCNN model with the Tensorflow object detection api. My dataset is alphabetically ordered (so there are a hundred adidas logo, then hundred apple logo etc.). And i would like it to be shuffled while training. I've put some values in the config file: train_input_reader:{ shuffle: true queue_capacity: some value min_after_dequeue : some other value} However whatever are the values, I'm putting in, algorithm is at first training on all of the a's logos (adidas, apple and so on) and only a lapse of time after starting to see the b's logos

C# creating function queue

南楼画角 提交于 2019-12-06 01:31:03
I have written a class called QueueManager: class QueueManager { Queue functionsQueue; public bool IsEmpty { get { if (functionsQueue.Count == 0) return true; else return false; } } public QueueManager() { functionsQueue = new Queue(); } public bool Contains(Action action) { if (functionsQueue.Contains(action)) return true; else return false; } public Action Pop() { return functionsQueue.Dequeue() as Action; } public void Add(Action function) { functionsQueue.Enqueue(function); } public void Add(Func<CacheObject,Boolean> function) { functionsQueue.Enqueue(function); } and when I create an

What is the best way to set up Queues for Laravel Events?

泄露秘密 提交于 2019-12-06 01:27:51
I have an event that is fired when I receive certain notifications. I want to Queue the event so that they aren't all fired at the same time but are Queued up as I receive them and then fired after the previous event completes. I want to know the best way to do this. Edit: Just for anyone in the future, setting up the database Queue driver is very straightforward and simple. You run the php artisan queue:table and change the driver to 'database'. My problem was that my app wasn't recognizing my QUEUE_DRIVER setting in my .env file for some reason. Laravel 5 has it's own way of dealing with