我有一个队列。如果它超过 X 大小,当我推送一个元素时,我想删除队列的第一个元素。(将弹出的最后一个元素和推入的第一个元素)
void ClientPlayerManager::queueTableMessage( const std::string& playerName, const std::string& message )
{
m_tableQ.push(std::make_pair(playerName,message));
if(m_tableQ.size() > m_maxTableMessages)
{
//m_tableQ.pop_back(); does not exist
}
}
Run Code Online (Sandbox Code Playgroud)
有没有办法用 std 队列来做到这一点?
谢谢
为了明天的测试,我需要能够:
解释堆栈和队列如何成为列表的特殊情况。
有谁知道我可以在哪里阅读此内容?谷歌搜索无法帮助我解决这个问题,这是“我们在课堂上讨论过这个问题,不要再问我”类型的问题之一。
我正在尝试使用此代码创建优先级队列,但找不到问题所在。有人告诉我我哪里错了。
<?php
class PriorityQueue implements Iterator , Countable
{
public function __construct() {
$flags = self::EXTR_DATA;
$items = array();
}
function compare ( mixed $priority1 , mixed $priority2 ){}
function count (){
return count($this->items);
}
function current (){
switch ($this->flags) {
case self::EXTR_BOTH:
$ret = array();
$ret['Patient'] = current($this->items);
$ret['Priority'] = $this->key();
break;
case self::EXTR_DATA:
$ret = current($this->items);
break;
case self::EXTR_PRIORITY:
$ret = $this->key();
break;
};
return $ret;
}
function extract (){
$ret = $this->current();
$this->next();
return $ret;
}
function …Run Code Online (Sandbox Code Playgroud) 我想知道如何清除(删除)jQuery 中所有排队的函数?这是我的代码:
\n\nvar a = $(\'<div class="notification" style="bottom:\'+ind+\'px">Message envoy\xc3\xa9 \'+i+\'<span class="close">x</span></div>\')\n .fadeIn(1000,"linear").delay(5000).fadeOut(3000,"linear");\nRun Code Online (Sandbox Code Playgroud)\n\n我想删除“fadeIn”、“delay”和“fadeOut”功能。我尝试使用 dequeue() 和 clearQueue() 但它无法正常工作。那么如何做到这一点呢?
\n我正在研究一个偶尔会收到新元素的列表。添加这些新元素后,我想对这些元素执行计算(准确地说,估计 KDE)。我很快意识到,如果这个列表无限增长,KDE 函数的计算将花费非常长的时间,所以我认为队列将是一个很好的数据结构。标准 Python 队列 ( https://docs.python.org/2/library/queue.html ) 不允许访问单个队列元素而不将它们从队列中“弹出”。还有其他选择吗?
换句话说:是否有一些Python库允许我获取队列元素而不弹出它?(或者允许对队列元素进行类似数组的索引?)
我正在 NGINX 上使用 MySQL 数据库创建 Laravel 4.2 应用程序。我正在尝试研究使用队列在任何给定时间减少 CPU 使用率的选项。
我希望任何排队的任务都保持在一定的内存使用水平之下;
但我不明白的是,如果正在运行的任务超过(或 work )--memory参数设置的限制,实际会发生什么php artisan queue:listen。
如果我跑
php artisan -h queue:work
在我的开发终端中,它简单地定义了
The memory limit in megabytes (default: 128)
但它没有说明如果该任务试图突破该限制将会发生什么。
我认为可能会发生两件不同的事情:
1)它将导致队列失败并最终出现在我的失败队列表上
2)它会以某种方式限制服务器完成任务的处理能力
我希望它是第二名;我对么?
众所周知,插入优先级队列的元素具有确定其优先级的值。例如,如果我有五个A,B,C,D,E具有优先级的元素(我们称之为优先级值priorityI):
A = 10, B = 5, C = 1, D = 3, E = 2。但是我如何编写一个可以定义两个优先级值的优先级队列,我的意思是:如果两个元素具有相同的值priorityI,则值priorityII决定应首先采用哪个元素,例如:
element A has priorityI = 3, and prioriotyII = 5
element B has priorityI = 3, and prioriotyII = 1
Run Code Online (Sandbox Code Playgroud)
那么第一个元素 B 将首先从队列中取出。
我正在尝试加载多个 xml 文件(位于服务器上),而不需要声明硬编码的文件名。为此,我尝试使用 d3.queue 库https://github.com/d3/d3-queue。
我已经实现了 xml 来强制布局满足我自己的需求(https://bl.ocks.org/mbostock/1080941),但是有一个关键缺陷,即我需要手动输入我想要的 xml 文件的名称加载...
给定(来自http://learnjsdata.com/read_data.html的调整示例):
queue()
.defer(d3.xml, "/mappings/Customer.hbm.xml")
.defer(d3.xml, "/mappings/Actor.hbm.xml")
.await(analyze);
function analyze(error, Customer, Actor) {
if(error) { console.log(error); }
// do stuff with Customer data, do stuff with Actor data
}
Run Code Online (Sandbox Code Playgroud)
并给出我对 xml 处理的实现:
d3.xml("mappings/Customer.hbm.xml","application/xml", function(error,xml){
if (error) throw error;
// do stuff with the data retrieved from Customer.hbm.xml
});
Run Code Online (Sandbox Code Playgroud)
如何组合以上两个片段,以便不必编写 xml 硬编码的位置并将所有参数传递给分析函数?任何朝着正确方向的推动将不胜感激。
在 psuedocode 中,我尝试编写如下代码(但我无法让它工作):
我打算并行运行多个作业,并按照此处的'NoneType' object is not callable示例使用作业队列,但它执行一次并在我尝试传递参数时引发异常。下面列出了代码:
import Queue
import schedule
import threading
import time
def job(arg):
print 'Argument is %s' % arg
def worker_main():
while True:
try:
job_func = jobqueue.get()
job_func()
except Exception as e:
print e
jobqueue = Queue.Queue()
schedule.every(2).seconds.do(jobqueue.put, job(1))
schedule.every(2).seconds.do(jobqueue.put, job(2))
worker_thread = threading.Thread(target=worker_main)
worker_thread.start()
while True:
try:
schedule.run_pending()
time.sleep(1)
except Exception as e:
print e
sys.exit()
Run Code Online (Sandbox Code Playgroud)
输出是:
Arg is 1
Arg is 2
'NoneType' object is not callable
'NoneType' object is not callable
'NoneType' …Run Code Online (Sandbox Code Playgroud) from google.cloud import tasks_v2
import json
GCP_PROJECT='test'
GCP_LOCATION='europe-west6'
def enqueue_task(queue_name, payload, process_url):
client = tasks_v2.CloudTasksClient()
parent = client.queue_path(GCP_PROJECT, GCP_LOCATION, queue_name)
task = {
'app_engine_http_request': {
'http_method': 'POST',
'relative_uri': process_url
}
}
if payload is None:
return False
payload = json.dumps(payload)
converted_payload = payload.encode()
task['app_engine_http_request']['body'] = converted_payload
return client.create_task(parent, task)
Run Code Online (Sandbox Code Playgroud)
当我尝试创建 Google Cloud 任务时,我不断收到以下错误。使用的 Google App Engine 运行时是 python38。它工作正常,但在使用 gcp CLI 部署后突然无法正常工作。
Traceback (most recent call last):
File "/layers/google.python.pip/pip/flask/app.py", line 2447, in wsgi_app
response = self.full_dispatch_request()
File "/layers/google.python.pip/pip/flask/app.py", line 1952, in …Run Code Online (Sandbox Code Playgroud) python queue python-3.x google-cloud-platform google-cloud-tasks
queue ×10
python ×4
beanstalkd ×1
c++ ×1
d3.js ×1
function ×1
javascript ×1
jquery ×1
laravel ×1
laravel-4 ×1
list ×1
php ×1
python-2.7 ×1
python-3.x ×1
scheduler ×1
stack ×1
xml ×1