Luke Plant avatar Luke Plant committed 8dd1afe

Cleaned up some code to do less work.

Comments (0)

Files changed (1)

 
      totalLength = B.length digits
 
-     -- The following functions, (makeMap, updateMap) may have trivial
-     -- implementations, but they allow us to change the datastructure WordMap
-     -- with minimal changes to the rest.
+     -- The following functions may have trivial implementations, but they allow
+     -- us to change the datastructure WordMap with minimal changes to the rest.
      makeMap :: WordList -> WordMap
-     makeMap = id
+     -- We can convert straight back to the WordList by removing entries
+     -- with no words, saving work later.
+     makeMap wl = filter (not . null . snd) wl
 
      updateMap :: WordMap -> WordList -> WordMap
      updateMap wordMap additional = wordMap ++ additional
 
-     -- get a list of all (position,length) where there are actually words
+     -- get a list of all (position,length) which have words
      findWordPositions :: WordMap -> [(Int,Int)]
-     findWordPositions wordMap = nub [ x | (x, words) <- wordMap, not $ null words ]
+     findWordPositions wordMap = nub $ map fst $ wordMap
 
-     -- get the entries where there are actually words
+     -- get a list of all entries which have words
      findWordEntries :: WordMap -> WordList
-     findWordEntries wordMap = filter (not . null . snd) wordMap
+     findWordEntries = id
 
 
 --
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.