An inverted index
I collect classic mystery novels, traditional British detective tales. These quaint, almost a century old puzzles have a soothing effect on me.
I do maintain a text file catalogue though (arrgh… no database for such a simple thing; a text file would do). The database I have is a csv
file with the author surnames and then the book titles. Now, what if I want to reread a book again but can't remember its full name or the author name? In such a scenario, we would use an inverted index to find the complete name.
An inverted index is when you remember a word in the title and seem to look up the author's name. The following Java program prints the inverted index for a few of these books:
class AuthorAndTitle { // 1 private final String authName; private final String title; public AuthorAndTitle(String authName, String title) { super(); this.authName = authName; this.title = title; } public String getAuthName() { return authName; } public String...