高效的TableModel实现 [英] Efficient TableModel implementation
问题描述
我的 TableModel
实现通常位于 ArrayList
上,以实现高效的随机访问性能。但是, ArrayList
的 remove(int)
实现看起来效率很低,因为它涉及制作 System.arrayCopy(...)
调用将所有后续元素后移1。
人们实现<$ c的方法$ c> TableModel s?我应该考虑一个更好的数据结构吗? ...也许是第3方库?
更多信息:我的表数据可能会缩小和增长,因此任何固定大小的缓冲区实现都将无法正常工作。 / p>
预先感谢。
您的过早优化问题。
在我的计算机上, System.arrayCopy()
可以复制大约13毫秒内有100万个数据元素。因此,我建议测量这是否真的是一个问题。在一般情况下,ArrayList比其他任何类似的数据结构更快,并且具有更好的内存性能。
使用 LinkedList
会使列表上的所有操作(包括 remove()
)变慢,因为您现在必须遍历每个操作的所有列表元素的一半(平均)。因此,大多数运算会从O(1)变为O(N / 2)。
My TableModel
implementations typically sit on an ArrayList
to allow for efficient random access performance. However, ArrayList
's remove(int)
implementation looks fairly inefficient as it involves making a System.arrayCopy(...)
call to shift all subsequent elements back by 1.
What approaches to people take to implementing TableModel
s? Is there a better data structure I should be considering? ... perhaps a 3rd party library?
Some more information: My table data can shrink and grow so any fixed-size buffer implementation isn't going to work.
Thanks in advance.
Your question reeks of "Premature Optimization".
On my computer, System.arrayCopy()
can copy 1 million elements of data in roughly 13ms. So I suggest to measure whether this is really an issue. In the general case, ArrayList is faster and has a better memory performance than any other similar data structure.
Using a LinkedList
would make all operations on the list (including remove()
) slower since you will now have to traverse half of all list elements for each operation (on average). So most operations would go from O(1) to O(N/2).
这篇关于高效的TableModel实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!