简体   繁体   English

高效的java数据结构来删除和检索信息?

[英]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: 我需要的特定品质是:

  1. get(index) 获取(索引)
  2. delete a certain number of entries that were added initially when the limit exceeds.(LIFO) 删除超过限制时最初添加的一定数量的条目。(LIFO)

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.

相关问题 具有高效添加,删除和随机的Java数据结构 - Java data structure that has efficient add, delete, and random Java:从文件存储/检索锻炼信息的最有效方法? - Java: Most efficient way to store/retrieve workout information from a file? 用于存储Java项目信息的合适数据结构 - suitable data structure for storing java project information 最有效的数据结构来表示Java中的线程注释? - Most efficient data structure to represent threaded comments in Java? 使用Java存储Web爬网程序的URI的最有效数据结构 - Best efficient data structure to store URIs for a web Crawler in Java 使数据结构成为线程安全的最有效方法(Java) - Most efficient way to make a data structure thread-safe (Java) Java:高效的数据结构,可存储没有“逻辑”重复项的对象 - Java: Efficient data structure to store object with no 'logical' duplicates 用于搜索三元组字符串的最有效的Java数据结构 - most efficient Java data structure for searching triples of strings 用于在文本Java中搜索单词的最有效的数据结构 - Most efficient data structure for searching for a word in text Java 一致且高效的双向数据结构实现(Java) - Consistent and efficient bi-directional data structure implementation (Java)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM