Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Merges the keywords for a single document into the master keywordsIndex
- * hash table. For each keyword, its Occurrence in the current document
- * must be inserted in the correct place (according to descending order of
- * frequency) in the same keyword's Occurrence list in the master hash table.
- * This is done by calling the insertLastOccurrence method.
- *
- * @param kws Keywords hash table for a document
- */
- public void mergeKeyWords(HashMap<String,Occurrence> kws) {
- // COMPLETE THIS METHOD
- // keywordsIndex.get(key).add(Occurrence)
- // ketwordsIndex.get(key).insertLastOccurence()
- }
- /**
- * Inserts the last occurrence in the parameter list in the correct position in the
- * same list, based on ordering occurrences on descending frequencies. The elements
- * 0..n-2 in the list are already in the correct order. Insertion is done by
- * first finding the correct spot using binary search, then inserting at that spot.
- *
- * @param occs List of Occurrences
- * @return Sequence of mid point indexes in the input list checked by the binary search process,
- * null if the size of the input list is 1. This returned array list is only used to test
- * your code - it is not used elsewhere in the program.
- */
- public ArrayList<Integer> insertLastOccurrence(ArrayList<Occurrence> occs) {
- if (occs.isEmpty() || occs.size() == 1)
- return null;
- Occurrence last = occs.get(occs.size()-1);
- ArrayList<Integer> checked = new ArrayList();
- int hi = occs.size() - 2; //last position is element to be sorted
- int lo = 0;
- int mid = 0;
- while (lo <= hi) {
- mid = (lo + hi)/2;
- checked.add(mid);
- if(last.frequency == occs.get(mid).frequency)
- break;
- else if (last.frequency > occs.get(mid).frequency)
- hi = mid - 1;
- else
- lo = mid + 1;
- }
- occs.add(mid, last);
- occs.remove(occs.size()-1);
- return checked;
- }
Add Comment
Please, Sign In to add comment