Pairing Functions

Wow, I did not know about it till last week and when I read about it, I was like where has this been all my life 🙂

Anyways its called Pairing Functions, which allows you to reduce 2 positive numbers into 1 and back.

Uses: Imagine you had a set of objects called Pair(long,long) and you wanted to search if a particular pair exists in that set, the usual way would be implement hashcode and equals . But with a pairing function you can reduce it to a set of longs.

In my experiments I saw an improvement of 30-40%.

For more info

http://sachiniscool.blogspot.com/2011/07/another-elegant-pairing-function.html

https://hbfs.wordpress.com/2011/09/27/pairing-functions/

http://szudzik.com/ElegantPairing.pdf

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s