Tuesday, March 22, 2011

Java an In - Memory Indexing Technique

Scenerio Given to me:

You have a set of XML documents that have data related to Bank. i.e name, place, account name, country etc. Users would like to search based on some important fields. For example a Bank data could have 10 columns and users would like to search based on 2-3 columns. Search has to be as fast as possible. 

My Solution:

1. Create an ArrayList that holds the list of BankData object. Each XML bank data corresponds to Java BankData object.
2. Create an Index object for each column that needs to be searched. Index object is a wrapper over java's TreeMap object where TreeMap's key is the column value and TreeMap's value is the index at which corresponding BankData exist in the ArrayList.
3. While reading each XML data construct a BankData object and put it in an ArrayList. Note the index at which BankData has been added in the ArrayList.
4. For each searchable columns, get the corresponding Index object and put column value and Arraylist index the TreeMap.
5. On search give the user input to the corresponding Index Object. It searches the TreeMap and identifies the ArrayList index and gets the real BankData from the ArrayList.

No comments:

Post a Comment