标签: queue

我将如何在 C# 中实现类型为 Dictionary<int, string> 的队列和迭代/入队/出队

我正在寻找实现 a Queueof 类型Dictionary<int, string>并能够迭代/入队/出队。

最终需要的是一个queueof int, string,无论它采取什么形式。

到目前为止,我有类似的东西:

  private static Queue<Dictionary<int, string>> requestQueue = new Queue<Dictionary<int, string>>();

  foreach (KeyValuePair<int, string> dictionaryListItem in dictionaryList)
  {
      requestQueue.Enqueue( dictionaryListItem ); // error
  }
Run Code Online (Sandbox Code Playgroud)

但似乎无法与上述排队。有人知道正确的语法吗?

c# queue dictionary types

2
推荐指数
1
解决办法
9860
查看次数

Python多处理队列文件描述符

我想知道队列是否有文件描述符以及如何找到它?

python queue multiprocessing

2
推荐指数
1
解决办法
1333
查看次数

数组队列 Java

我正在开发一个为三个不同的人订购工作的程序,所以我使用了队列,因为工作需要先进先出。作业是存储三个不同字符串的数组。这是我目前拥有的相关代码。

Queue<String[]> MMT1Jobs  = new LinkedList<String[]>();
Queue<String[]> MMT2Jobs  = new LinkedList<String[]>();
Queue<String[]> MMT3Jobs  = new LinkedList<String[]>();
//job array layout should look like this [registration number][grid reference][who is assign to the job]
String[] MMT1CurrentJob = new String[3];
String[] MMT2CurrentJob = new String[3];
String[] MMT3CurrentJob = new String[3];
String[] MMT1LastJob = new String[3];
String[] MMT2LastJob = new String[3];
String[] MMT3LastJob = new String[3];
String[] justScanned = new String[3];
//check if there is any Jobs open
File jobsOpenFile = new File("JOBS-OPEN.txt");
if(jobsOpenFile.exists())
{ …
Run Code Online (Sandbox Code Playgroud)

java arrays queue

2
推荐指数
1
解决办法
6057
查看次数

C# System.ArgumentException:目标数组不够长

我有一个通用的 Queue 对象,它是从 SerialPort.DataReceived 方法提供的。

调用 ToArray() 方法时,有时会出现异常“目标数组不够长”。编码:

        byte[] tmpArray;

        try
        {
            tmpArray = queue.ToArray();
        }
        catch (Exception ex) 
        {
Run Code Online (Sandbox Code Playgroud)

作为记录:queue.Count 永远不会超过 500。

虽然这很可能是线程问题,但我不理解异常。队列的 ToArray() 方法中的目标数组何时会太短?

如果这是一个线程问题,那么在将数据从 SerialPort 获取到队列时的最佳实践是什么?

BTW:我在写之前锁定队列。也许我也应该在 ToArray() 之前锁定它?

c# queue serial-port thread-safety

2
推荐指数
1
解决办法
6431
查看次数

如何使用 UVM 实用程序函数打印整个队列/数组?

对于使用`uvm_field_queue_int实用宏的UVM 对象,调用时 UVM 不会打印出整个队列my_object.print()

# -----------------------------------------
# Name Type Size Value
# -----------------------------------------
# my_object my_object - @443
# data_q da(integral) 16 -
# [0] integral 32 'h203f922b
# [1] integral 32 'he4b3cd56
# [2] integral 32 'hd7477801
# [3] integral 32 'h3a55c481
# [4] integral 32 'h2abf98c4
# ... ... ... ...
# [11] integral 32 'hac0d672b
# [12] integral 32 'h3ba2cb5d
# [13] integral 32 'hbe924197
# [14] integral 32 'h3cc6d490
# [15] integral 32 …
Run Code Online (Sandbox Code Playgroud)

printing queue system-verilog uvm

2
推荐指数
1
解决办法
1万
查看次数

how do i store and get a queue of structure?

How do I store and get value of structure into a queue where I have 2 values? I wanna queue this few values.

| 4 , 2 |

| 3, 5 |

Where by 4,2 and 3,5 can be a variable such as

primaryQ.push(a, b);
Run Code Online (Sandbox Code Playgroud)

My structure:

struct primarytemp{
    double process;
    double secondary;
};
Run Code Online (Sandbox Code Playgroud)

Here's how I declared my main:

int main(){
    queue<primarytemp> primaryQ;
    primaryQ.push(4, 2);
}
Run Code Online (Sandbox Code Playgroud)

c++ queue struct structure

2
推荐指数
1
解决办法
1万
查看次数

如何将数组的数据直接放入PriorityQueue

你如何将数组的数据直接放入PriorityQueue哪个实现Queue接口?

ContestantFilter [] contestantFilter = new ContestantFilter [50];
contestantFilter [0] = new ContestantFilter("Agnesy Pricillia","IF110026");
contestantFilter [1] = new ContestantFilter("Ellen Shie ","IF110103");
contestantFilter [2] = new ContestantFilter("Wilma Yue Gunawan","EL110021");
.................
.................

Queue<ContestantFilter> queue = new PriorityQueue<ContestantFilter>(1,
                new Comparator<ContestantFilter>() {
                     @Override
                    public int compare(ContestantFilter t1, ContestantFilter t2) {
                        return t1.getID().compareTo(t2.getID());}});
Run Code Online (Sandbox Code Playgroud)

我试过

for(ContestantFilter c : contestantFilter ){ queue.add(c);}
Run Code Online (Sandbox Code Playgroud)

但它很慢。

就像是 :

queue = ((Queue<ContestantFilter >) Arrays.asList(contestantFilter );
Run Code Online (Sandbox Code Playgroud)

铸造不起作用。

java queue collections

2
推荐指数
1
解决办法
7498
查看次数

如何在java中的Queue前面添加一个元素?

我正在使用Queue<T> q1并且我知道将q1.offer();在队列末尾添加一个元素。但是现在,我想要做的是在队列前面添加一个元素,这是队列无法实现的。我能想到的可能方法是

  • 使用双端队列,我可以在前面和最后添加元素。
  • 反转 q1,在队列末尾添加元素并再次反转。

现在,作为一个非程序员的人,我不确定如何编写这些方法;哪个更经济,更容易做。

我在 1) 中遇到的问题是将现有 Queue 转换为 Deque,反之亦然;并在 2) 如何使用Collections.reverseOrder();来反转现有的队列。

java queue reverse deque

2
推荐指数
1
解决办法
2万
查看次数

在 python 中使用 thread.start() 返回值(使用队列)

我想创建一个函数的多线程版本。我发现t.start()返回None,所以我必须使用队列。我搜索了文档,但我不明白如何在我的示例中使用它。

这是函数:

def derivative(lst, var):  # Example of lst =  [1 + [3 * x]]
    if len(lst) == 1:       
        return derive_solver(lst[0], var)

    if lst[1] == '+':
        return [derivative(lst[0], var), '+', derivative(lst[2], var)]

    if lst[1]  == '*':
        return [[derivative(lst[0], var), '*', lst[2]], '+', [lst[0], '*', derivative(lst[2], var)]]
Run Code Online (Sandbox Code Playgroud)

这是我尝试多线程该功能:

def derivative(lst, var):  # Example of lst =  [1 + [3 * x]]
    if len(lst) == 1:       
        return derive_solver(lst[0], var)

    if lst[1] == '+':
        t1 = threading.Thread(target = derivative, …
Run Code Online (Sandbox Code Playgroud)

python queue multithreading

2
推荐指数
1
解决办法
1万
查看次数

Laravel 队列和跨类的持久变量

在那里,我潜入了队列的世界及其所有美好之处,这让我感到震惊:

由于 Laravel 对信息进行序列化,当应用程序将任务推送到队列时,会话数据会丢失。

了解了如何将数据发送到队列后,仍然存在一个问题:

鉴于队列将信息推送到单个类,

在此任务的整个持续时间内,我如何使该信息在其他类中持久化(例如会话)?

编码示例:

//Case where the user object is needed by each class
class queueme {
    ...
    //function called by queue
    function atask($job,$data) 
    {
         //Does xyz
         if(isset($data['user_id'])
         {
              //Push user_id to another class
              anotherclass::anothertask($data['user_id']);
         }
    }
}

class anotherclass {
    ...
    function anothertask($user_id)
    {
         //Does abc
         //Yup, that anotherofanother class needs user_id, we send it again.
         anotherofanotherclass::yetanothertask($user_id);
    }
}
Run Code Online (Sandbox Code Playgroud)

上面的代码说明了我的问题。

如果我的课程需要此信息,我是否必须传递$user_id或User对象?

没有更干净的方法吗?

php queue laravel laravel-4

2
推荐指数
1
解决办法
1721
查看次数