Hashing
Hashing is a system that allow content to be stored in a way that can be codified thanks to some math, and is very useful for efficiently store data. Twitter, Tumblr and other social networks, and several pages and programs works internally with this system. This is the security key for making something secure enough or weak. The more you know!
Now, this is a happy easy example o hashing, with some cyberpunk movies as data examples.
First of all, we think of a blank table with numbered positions from 0 to n. It looks like this:
and continue with a content table, this case I’m using cyberpunk movies:
identification number[ Matrix ] id number[ Blade Runner ] … id number […]
We need now a key number, this time we will choose n. now, we do this:
Matrix is the number 12, and the key is 11. The hash will be
h(12)= 12%11=1 (remember % returns the reminder of a division, not the ratio), so 12, which had the number position 0 in his content table, goes in the location 1 of the black table. We do the same with the rest contents.
But shit may happen and the result of the h(m)= m%n may be a location which is already chosen. For example, if the key is 5, we will encounter that 2 and 3 locations appear more than once. Then, we can have a couple of solutions. We use something called linked lists, and now each position can have a panel with 3 options. First, as the simple example before, the content. In the case of MATRIX, the content is 12. Secondly, the original location of MATRIX, which was as told before, 0. and, the third ones remains blank until another one want to be stored in the same position, and that third one will be used as a pointer for the next panel. It may sound confusing but take a look at this, it’s pretty easy, actually:
Finally, there’s another option. Let’s now imagine we want to add another 3 movies, with the numbers 55,23 and 60. Those have the result of 0,1 and 5 in the first system (n=11). instead of using the last method, we can try to find a new location until it fits. How?
h(55)= 55%11= 0 //ALREADY CHOSEN! SO…
h1(55)= (h(55)+ (2-1) %11)= (0+1)%11= 1%11= 1 //ALSO CHOSEN, NEXT
h2(55)= (h1(55)+(2-1) %11)=(1+1)%11= 2%11= 2//ONE MORE TIME
h3(55)= (2+1) % 11 = 3 %11= 3 //FREE!
so the movie with number 55 is stored in location 3. The same happens with the rest. Take a look:
And this is it, there’s way more about, but these are the basics, and I find it interesting. This system is being used in your computer all the time, every day, and you may don’t know it so!