1 28 29 package com.caucho.db.index; 30 31 34 public class KeyCompare { 35 38 public int compare(byte []keyBuffer, int keyOffset, 39 byte []block, int offset, int length) 40 { 41 for (; length > 0; length--) { 42 byte keyByte = keyBuffer[keyOffset++]; 43 byte blockByte = block[offset++]; 44 45 if (keyByte < blockByte) 46 return -1; 47 else if (blockByte < keyByte) 48 return 1; 49 } 50 51 return 0; 52 } 53 54 public String toString(byte []buffer, int offset, int length) 55 { 56 StringBuilder sb = new StringBuilder (); 57 58 for (int j = 0; j < length; j++) { 59 int ch = buffer[offset + j]; 60 61 if (ch == 0) 62 break; 63 64 sb.append((char) ch); 65 } 66 67 return sb.toString(); 68 } 69 } 70 | Popular Tags |