I need an ordered data structure with O(1) indexOf operation. I store object pointers in the data structure. Any ideas? Some sort of LinkedHashMap?
See what "indexOf" means: List.indexOf(Object)
With a hash table, you can access objects by the key, so this structure is high-speed for lookups. Hash tables are faster than the arrays for lookups.
The data structure should be stored in disk, during or at the end of the indexing procedure. The algorithm should quickly ( O(log(n)) ) find the occurrences of any subset of the text. For instance, if the input is book it should find all occurrences of it, but this should also be true for book is and The book is .
arrays - Efficient data structure for fast random access, search, insertion and deletion - Stack Overflow.
Stack is a linear data structure in which the insertion and deletion operations are performed at only one end. In a stack, adding and removing of elements are performed at single position which is known as "top". That means, new element is added at top of the stack and an element is removed from the top of the stack.
This question is ambiguous to begin with.
indexOf(..)
operation.indexOf(..)
the only responsibility of the collection. Simply put, one way to do this would be to maintain a that would index each Object
or keys with the list of indices.
HashMap<Object, List<Integer>>
Again, this is vague, probably would help if you specify the exact nature of problem you're trying to solve.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With