I have been struggling with a very simple problem... I am working with a 4 dimensional cube using AVL trees... now the problem is a performance related one... basically I have to compare billions of 64 bit numbers... (because my key is 64bit comprising the 4 dimensions of 16bits each)...
The problem is not that I can't compare 2 64-bit numbers, but rather I need to do it in as few as possible clock cycles.
Unfortunately my AVL Tree template has a signature of "int CompareKeyNode(key k, handle h)"
Under the hood I have two __int64 numbers lhs & rhs, unfortunately the contract of this method is: 1. lhs==rhs return 0 2. lhs > rhs return 1 3. lhs < rhs return -1
Now if the above method expected an __int64 number I could simply do a (METHOD A) return lhs - rhs;
Unfortunately it only needs a 32 bit integer, so I have to resort to something akin to ((METHOD B)) ie. return lhs == rhs ? 0 : (lhs < rhs ? -1 : 1)
The problem to me is that to load my data using (METHOD A) takes 60 secs whilst (METHOD B) takes 117 seconds.
Unfortunately (METHOD A) is incorrect as it loses precision on the return for casting the lhs-rhs statement.
The processing time is crucial to me and I am sure there must be a simple efficient answer which is eluding me right now...
Does anybody have an idea on how to solve this? Or perhaps any suggestions?
I am working in VC++ (un-managed) but surely .NET/Java must have solved this problem in there JITing/VM stage... otherwise they would be taking a huge performance hit.
PS: Have tried memcmp() but not good enough...