[
https://issues.apache.org/jira/browse/HBASE-8201?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13703833#comment-13703833
]
Nick Dimiduk commented on HBASE-8201:
-------------------------------------
bq. This kind of code makes order encapsulation leak.
Agreed. How about something like the following?
{noformat}
assert header == 0x30 || header == Order.DESCENDING.apply((byte) 0x30);
{noformat}
bq. I am not getting something here...
The idea is to create a mask that supports sort order preservation for negative
numbers while also accounting for the range of negative values being one larger
than the range of positive values. From the
[spec|http://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html],
{quote}
*int*: The int data type is a 32-bit signed two's complement integer. It has a
minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive)
{quote}
So this logic creates a mask that will invert the sign bit and maintain the
range.
{code}
for (int i : new int[] { 5, -5, Integer.MAX_VALUE, Integer.MIN_VALUE }) {
int j = (i >> Integer.SIZE - 1) | Integer.MIN_VALUE;
int k = i ^ j;
System.out.println("Input: 0x" + Integer.toHexString(i));
System.out.println("Shifted: 0x" + Integer.toHexString((i >> Integer.SIZE
- 1)));
System.out.println("MIN_VAL: 0x" +
Integer.toHexString(Integer.MIN_VALUE));
System.out.println("Mask: 0x" + Integer.toHexString(j));
System.out.println("Result: 0x" + Integer.toHexString(k));
System.out.println();
}
{code}
{noformat}
Input: 0x5
Shifted: 0x0
MIN_VAL: 0x80000000
Mask: 0x80000000
Result: 0x80000005
Input: 0xfffffffb
Shifted: 0xffffffff
MIN_VAL: 0x80000000
Mask: 0xffffffff
Result: 0x4
Input: 0x7fffffff
Shifted: 0x0
MIN_VAL: 0x80000000
Mask: 0x80000000
Result: 0xffffffff
Input: 0x80000000
Shifted: 0xffffffff
MIN_VAL: 0x80000000
Mask: 0xffffffff
Result: 0x7fffffff
{noformat}
> Implement serialization strategies
> ----------------------------------
>
> Key: HBASE-8201
> URL: https://issues.apache.org/jira/browse/HBASE-8201
> Project: HBase
> Issue Type: Sub-task
> Components: Client
> Reporter: Nick Dimiduk
> Assignee: Nick Dimiduk
> Fix For: 0.95.2
>
> Attachments:
> 0001-HBASE-8201-OrderedBytes-provides-order-preserving-se.patch,
> 0001-HBASE-8201-OrderedBytes-provides-order-preserving-se.patch,
> 0001-HBASE-8201-OrderedBytes-provides-order-preserving-se.patch,
> 0001-HBASE-8201-OrderedBytes-provides-order-preserving-se.patch,
> 0001-HBASE-8201-OrderedBytes-provides-order-preserving-se.patch,
> 0001-HBASE-8201-OrderedBytes-provides-order-preserving-se.patch,
> 0001-HBASE-8201-OrderedBytes-provides-order-preserving-se.patch,
> 0001-HBASE-8201-OrderedBytes-provides-order-preserving-se.patch
>
>
> Once the spec is agreed upon, it must be implemented.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira