[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: ordered indexing for integers



Hallvard B Furuseth wrote:
Also overflow gives wrong ordering:
    value 0x100000000: index 0480000000
    value  0x80000000: index 0580800000
I'm too tired to figure out what the code does at overflow now, and
maybe I misunderstood the discussion earlier, but it should give the
right _ordering_ for overflow even if it can't make a very exact index.

Right. All fixed.

I wrote:
To get the correct ordering, use normal (fully sign-extended) two's
complement but with the sign bit inversed.  (Same as value + max
positive value + 1)

The sign bit was already being handled, but I was zero-extending instead of sign-extending. (doh...)


Actually, looking at lutil_str2bin() one's complement would be easier:-)

It might have been, but the current 2's complement is BER-compatible.

And maybe it needs to turn '-0' into '0'?  I think that's invalid LDAP
Integer syntax so it doesn't matter in that context, but still.

Right, invalid; integerValidate will reject it so it'll never get here.

--
  -- Howard Chu
  Chief Architect, Symas Corp.  http://www.symas.com
  Director, Highland Sun        http://highlandsun.com/hyc/
  Chief Architect, OpenLDAP     http://www.openldap.org/project/