S
solandre
my motivation is as follows:
i have to binarysearch several million times an long[] that is several
million items big. this costs time, although i use
Array.Binarysearch<long>. so i try to keep the Compare-method as lean
as possible, as it is summoned several 10 million times.
in case of an integer the fastest way would be this i think:
public int Compare(int a, int b)
{
return a-b;
}
the prob is the returnval needs to be an integer, because the
binarysearch-method works with an int as far as i know. if i would
write...
public int Compare(long a, long b)
{
return a-b;
}
its an error, or i write...
public int Compare(long a, long b)
{
return (int)(a-b);
}
i loose information, likely leading to incorrect results.
any idea for a superfast way for long-types or anybody who knows a
binarysearch-method that takes a long-type as input?
thanks
i have to binarysearch several million times an long[] that is several
million items big. this costs time, although i use
Array.Binarysearch<long>. so i try to keep the Compare-method as lean
as possible, as it is summoned several 10 million times.
in case of an integer the fastest way would be this i think:
public int Compare(int a, int b)
{
return a-b;
}
the prob is the returnval needs to be an integer, because the
binarysearch-method works with an int as far as i know. if i would
write...
public int Compare(long a, long b)
{
return a-b;
}
its an error, or i write...
public int Compare(long a, long b)
{
return (int)(a-b);
}
i loose information, likely leading to incorrect results.
any idea for a superfast way for long-types or anybody who knows a
binarysearch-method that takes a long-type as input?
thanks