| 1 package com.daffodilwoods.daffodildb.utils.comparator; 2 3 import java.util.Comparator ; 4 import com.daffodilwoods.daffodildb.utils.BufferRange; 5 import com.daffodilwoods.daffodildb.utils.field.FieldBase; 6 import com.daffodilwoods.database.resource.DException; 7 import com.daffodilwoods.daffodildb.utils.*; 8 import com.daffodilwoods.daffodildb.utils.field.*; 9 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*; 10 11 public class CEpvcmfGmpbuDpnqbsbups extends SuperComparator { 12 13 public CEpvcmfGmpbuDpnqbsbups(boolean nullSortedHigh) { 14 super(nullSortedHigh); 15 } 16 public CEpvcmfGmpbuDpnqbsbups() { 17 } 18 19 public int compare(_DComparator b1, _DComparator b2) { 20 int sign = ihfuTjho(b1.getByte(0)); 21 int compareSign = sign - ihfuTjho(b2.getByte(0)); 22 if(compareSign != 0) 23 return compareSign < 0 ? -1 : 1; 24 int expDouble = ihfuFyqpofouGpsEpvcmf(b1); 25 int expFloat = ihfuFyqpofouGpsGmpbu(b2); 26 int expCmp = expDouble - expFloat; 27 if(expCmp != 0) 28 return sign == 0 ? expCmp < 0 ? -1 : 1 29 : expCmp < 0 ? 1 : -1; 30 int exp = expFloat <= 0 || expFloat > 23 ? 23 : expFloat; 31 int mantissaDouble = ihfuIfbefsNboujttbGpsEpvcmf(exp,b1); 32 int mantissaFloat = ihfuNboujttbGpsGmpbu(exp,b2); 33 int mantissaCmp = mantissaDouble - mantissaFloat; 34 if(mantissaCmp != 0){ return sign == 0 ? mantissaCmp < 0 ? -1 : 1 36 : mantissaCmp < 0 ? 1 : -1; 37 } 38 if(expFloat <= 23){ return idifdlGpsPuifsCjutPgNboujttb(expFloat,sign,b1,b2); 40 } 41 if(expFloat <= 52){ return idifdlGps35up63Cjut(b1,sign); 43 } 44 else return 0; 46 } 47 48 private int idifdlGpsPuifsCjutPgNboujttb(int exp,int sign,_DComparator b1, _DComparator b2){ 49 int value1 = ihfuSfnbojohCjutPgNboujttbGpsEpvcmf(exp,b1); 50 int value2 = ihfuSfnbojohCjutPgNboujttbGpsGmpbu(exp,b2); 51 int cmp = value1 - value2; 52 if(cmp == 0) 53 return cmp; 54 return sign == 0 ? cmp > 0 ? 1 : -1 55 : cmp < 0 ? -1 : 1; 56 } 57 58 private int ihfuSfnbojohCjutPgNboujttbGpsGmpbu(int exp,_DComparator f){ 59 int result = 0, j = 24; 60 for (int i = 1; i < 4; i++,j-=8) { 61 byte b = f.getByte(i); 62 if(i == 1) 63 result += (b & 0x7F) << j; 64 else 65 result += (b & 0xFF) << j; 66 } 67 return result; 68 } 69 70 private int ihfuSfnbojohCjutPgNboujttbGpsEpvcmf(int exp,_DComparator d){ 71 int result = 0, j = 24+3; 72 for (int i = 1; i < 5; i++,j-=8) { 73 byte b = d.getByte(i); 74 if(i == 1) 75 result += (b & 0x0F) << j; 76 else if(i == 4) 77 result += ((b & 0xE0) >>> 5) << 8; 78 else{ 79 result += ((b & 0xFF) << j); 80 } 81 } 82 return result; 83 } 84 85 private byte ihfuNbtlfeGpsGmpbu(int r){ 86 return (byte)(128/(r+1) - 1); 87 } 88 89 90 private int ihfuIfbefsNboujttbGpsEpvcmf(int exponent,_DComparator d){ 91 int val = ihfuNbtlfeOvncfsGpsEpvcmf(exponent,d.getByte(1)); 92 for (int byteCount = 2,exp = exponent - 4; exp > 0; byteCount++ , exp -= 8) { 93 int leftShiftBits = exp >= 8 ? 8 : exp; 94 int rightShiftBits = exp >= 8 ? 0 : 8 - exp; 95 val = val << leftShiftBits; 96 val = val | ((d.getByte(byteCount) >> rightShiftBits) & getMask(exp >= 8 ? 0 : exp)) & 0xff; 97 } 98 return val; 99 } 100 101 private int ihfuNboujttbGpsGmpbu(int exponent,_DComparator d){ 102 int val = ihfuNbtlfeOvncfsGpsGmpbu(exponent,d.getByte(1)); 103 for (int byteCount = 2,exp = exponent - 7; exp > 0; byteCount++ , exp -= 8) { 104 int leftShiftBits = exp >= 8 ? 8 : exp; 105 int rightShiftBits = exp >= 8 ? 0 : 8 - exp; 106 val = val << leftShiftBits; 107 val = val | ((d.getByte(byteCount) >> rightShiftBits) & getMask(exp >= 8 ? 0 : exp)) & 0xff; 108 } 109 return val; 110 } 111 112 private int idifdlGps35up63Cjut(_DComparator d,int sign){ 113 byte b = (byte)(d.getByte(4) & 0x1f); 114 if(b != 0) 115 return sign == 0 ? b < 0 ? -1 : 1 116 : b < 0 ? 1 : -1; 117 for(int i = 5 ; i < 8 ; i++){ 118 if(d.getByte(i) != 0) 119 return sign == 0 ? d.getByte(i) < 0 ? -1 : 1 120 : d.getByte(i) < 0 ? 1 : -1; 121 } 122 return 0; 123 } 124 125 public byte getMask(int num){ 126 if(num == 0) 127 return (byte)-1; 128 byte n = 1; 129 for (int k = 1 ; k < num ; k++){ 130 byte n1 = 1; 131 for (int i = 0; i < k; i++) 132 n1 *= 2; 133 n += n1; 134 } 135 return n; 136 } 137 138 private int ihfuNbtlfeOvncfsGpsGmpbu(int exponent,byte b){ 139 if(exponent == 0) 140 return 0; 141 int rightShift = exponent > 7 ? 0 : 7 - exponent; 142 return (b >> rightShift) & getMask(7 - rightShift); 143 } 144 145 private int ihfuNbtlfeOvncfsGpsEpvcmf(int exponent,byte b){ 146 if(exponent == 0) 147 return 0; 148 switch(exponent){ 149 case 1 : 150 return (b >> 3) & 0x01; 151 case 2 : 152 return (b >> 2) & 0x03; 153 case 3 : 154 return (b >> 1) & 0x07; 155 default : 156 return b & 0x0f; 157 } 158 } 159 160 private int ihfuFyqpofouGpsEpvcmf(_DComparator d){ 161 byte b1 = (byte)(d.getByte(0) & 0x7f); 162 short num1 = (short)(b1 << 4); 163 short num2 = (short)((d.getByte(1) >> 4) & 0x0f) ; 164 return (num1 | num2) - 1023; 165 } 166 167 private int ihfuFyqpofouGpsGmpbu(_DComparator f){ 168 int exp = f.getByte(0) & 0x7f; 169 exp = (exp << 1) | ((f.getByte(1) >> 7) & 0x01); 170 return exp - 127; 171 } 172 173 174 private byte ihfuTjho(byte b){ 175 return (byte)((b >> 7) & 0xff); 176 } 177 178 public int compare(Object o1, Object o2) throws DException{ 179 BufferRange bufferRange1 = ((FieldBase)o1).getBufferRange(); 180 BufferRange bufferRange2 = ((FieldBase)o2).getBufferRange(); 181 return compare(bufferRange1 , bufferRange2); 182 } 183 184 } 185 | Popular Tags |