The Importance of Hashing
Neuroscience

The Importance of Hashing


People who are just beginning to code make a lot of mistakes and do a lot of stupid things. I once used to struggle with parsing thorough every line of a file before I learned that it would be much easier to use split-functions and similar lists. One common mistake people make is that they need to store large amounts of data and parse through them every time they need to access that information. But, with a bit more expertise, those newbies can throw away those "for" loops and sort-methods. There's a new kid in town. And his name is "Hashing."

The following code uses two different lists indices_start and indices_end. These two lists have the start and end positions of certain areas in a very long sequence, and the computer must go from one list to the other to identify those regions when parsing through a string "s".

for i in range(len(s)):
    c+=1
    if c in indices:
        line=int(indices_start.index(c))
        for i in s[i:indices_end[line]+1]:

            s2+="N"

The problem is that this takes forever and a half to run. But, if we just replaced the two lists with a single hash (or dictionary) which we will name indices, then the program runs like clockwork.

for i in range(len(s)):
    c+=1
    if c in indices:
        line=int(indices[c])
        for i in s[i:line+1]:

            s2+="N"

Just goes to show how much of a difference code optimization can make. 

END

(Excuse me for that last line. My Fortran is leaking.)




- Link Feast
In case you missed them - 10 of the best psychology links from the past week: "The brain, the most mysterious object in the universe, but it can still make you behave like a bit of an idiot," said Dara Ó Briain, introducing the latest edition of his...

- Looking For Longer But 'seeing' Less
Looking for too long at something can sometimes make it harder to ‘see’ what you are looking for, according to Li Zhaoping and Nathalie Guyader at UCL. In an odd-one-out type task, a single line orientated like this / was hidden among dozens of lines...

- Dope-a-mine!
After a long hiatus, Dan Dright is posting again at N E U R O N E R D and has this to say about dopamine (and a new article in Science about impulsive rats): That's why they call it Dope-a-mine Once again the chicken/egg argument is revisited vis-a-vis...

- Introducing The Brain Maps Api
The Brain Maps API lets you embed Brain Maps in your own web pages with JavaScript. Future versions will enable you to add overlays to brain maps (including markers and polylines) and display shadowed "info windows". The Brain Maps API is a free service,...

- Usability: Worth The Effort?
Today I'm speaking at Simmons GSLIS West about usability. You can see the useful links I've gathered over the years on my Simmons wiki, which lists my favorite usability articles. It's also got a copy of my PowerPoint presentation, in case...



Neuroscience








.