[英]Efficient java data structure to delete and retrieve information?
I have a situation where I have need a data structure that I can add strings to. 我遇到一种需要添加字符串的数据结构的情况。 This data structure is very large.
该数据结构非常大。
The specific qualities I need it have are: 我需要的特定品质是:
I've tried using an ArrayList but the delete operation is o(n) and for a linkedList the traverse or get() operation will be o(n). 我试过使用ArrayList,但删除操作为o(n),对于链表,遍历或get()操作将为o(n)。
What other options do I have? 我还有什么其他选择?
LinkedHashSet might be of interest. LinkedHashSet可能很有趣。 It is effectively a HashSet but it also maintains a LinkedList to allow a predictable iteration order - and therefore can also be used as a FIFO queue, with the nice added benefit that it can't contain duplicate entries.
它实际上是一个HashSet,但它还维护一个LinkedList以允许可预测的迭代顺序-因此也可以用作FIFO队列,其好处是它不能包含重复的条目。
Because it is a HashSet too, searches (as opposed to scans) can be O(1) if they can match on equals()
因为它也是一个HashSet,所以如果搜索(与扫描相反)可以在
equals()
上匹配,则可以为O(1 equals()
You can have a look at this question and this too. 你可以看看这个问题, 这也。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.