Reputation: 23
I am implementing inverted index in haskell. I have already made the case where my code would create the inverted index of every word in the list of documents that i provide. and then write this index to a file called inv.txt which would be something like:
("this",[d1,d2,d5])
("is",[d3,d4,d16])
("hello",[d1])
However, I want to add an additional case, where if I add a new document to my folder, and call the function, the "inv.txt" gets updated according to the newly added document. so it now becomes something like
("this",[d1,d2,d5,new Doc])
("is",[d3,d4,d16])
("hello",[d1])
("get",[new Doc])
but I can not think of an approach to go about it. is this somehow possible in haskell? (without re writing the whole file, like using seekg or peekg functions or something)?
Upvotes: 0
Views: 46
Reputation: 52039
Since your primary use case is adding a document to the index, how about this:
For example, suppose your index file contains the lines:
("this",[d1,d2,d5])
...
("this", [d6])
When you encounter the first "this" pair you would create the pair in your Map, and when you encountered the second "this" pair you would append/prepend d6
to the current list associated with the key.
Upvotes: 1