本文介绍了Dart中的DoubleLinkedQueue和ListQueue有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Dart核心API有两个用于实现 界面, DoubleLinkedQueue<E> ListQueue<E> .

The Dart core API has two classes that implement the Queue<E> interface, DoubleLinkedQueue<E> and ListQueue<E>.

两个类的文档几乎完全相同,唯一明确提到的区别是ListQueue<E>文档中的以下注释:

The documentation of both classes is almost identical, the only difference that is explicitly mentioned is the following note in the ListQueue<E> documentation:

在实现方面,它们之间的实际区别是什么?何时应使用哪种实现?

What is the actual difference between them implementation-wise and when should which implementation be used?

推荐答案

DoubleLinkedQueue基本上是在双向链接列表顶部实现的队列.这意味着删除元素在任意位置的速度很快,因为它只需要调整指针即可.

The DoubleLinkedQueue is basically a Queue implemented on top of a double-linked list. This means that removing elements at arbitrary positions in it is fast, since it only requires the adjustment of pointers.

ListQueue在列表顶部实现.第一个和最后一个是列表的索引.通常,这是更有效的实现,因为它比双向链接列表具有更少的内存开销.

The ListQueue is implemented on top of a List. First and last are indices into the list. In general this is the more efficient implementation, since it has less memory-overhead than the double-linked list.

您可以在此处

大多数时候您想使用ListQueue.因此,Queue接口默认为ListQueue(即Queue()返回ListQueue).

Most of the time you want to use the ListQueue. For that reason, the Queue interface defaults to the ListQueue (i.e. Queue() returns a ListQueue).

如果需要选择性地删除队列中的元素,DoubleLinkedQueue实现最有用.这是一种相对罕见的情况,该类在dart库中的主要原因是DoubleLinkedQueueListQueue之前存在.因为我们已经有了DoubleLinkedQueue,所以我们保留了它.如果我们从ListQueue开始,我们可能不会添加DoubleLinkedQueue.

The DoubleLinkedQueue implementation is mostly useful if you need to selectively remove elements inside the queue. It's a relatively rare scenario, and the main-reason the class is in the dart-libraries, is that the DoubleLinkedQueue existed before the ListQueue. Since we already had the DoubleLinkedQueue we kept it. If we had started out with the ListQueue we probably wouldn't have added the DoubleLinkedQueue.

这篇关于Dart中的DoubleLinkedQueue和ListQueue有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 05:26