File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes HashMap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "HashMap" Watch "HashMap" New topic


kantri yama

Joined: Oct 26, 2008
Posts: 1

I need to implement a storage structure(inverted index) for information retrieval project. For each keyword, I need to store the document ID in which it is present and position of occurrences. For ex

inverted index :
a->[doc 1, (1,2,4)], [doc2, (2)]
b->[doc 1, (3)], [doc2, (3)]
c->[doc 2, (1)]

i.e 'a' is present in doc 1 at 1,2,and 4 positions and in doc 2 at 2nd position. I am puzzled about how to implement hashmap for this index. I couldn't get an idea about how to implement [doc 1, (1,2,4)] as one part, and [doc2, (2)] as another part using multiple values for each key. Please help me.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46397
Welcome to JavaRanch

Bit difficult to know what would be best, just at a quick look, but can you put those numbers into a List<Integer>?
Then you could have a Map<Something, List<Integer>>; whenever you get a new Something you can add the number to the List.

Or can you create a Location class and have a List<Location>, then Map<Something, List<Location>>?
I agree. Here's the link:
subject: HashMap
jQuery in Action, 3rd edition