| | |
| | | * CDDL HEADER END |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | */ |
| | | |
| | | |
| | |
| | | |
| | | /** |
| | | * Implementation of ComparatorBuffer interface. Used to compare keys when |
| | | * they are DN index is being processed. |
| | | */ |
| | | public static |
| | | class DNComparator implements IndexBuffer.ComparatorBuffer<byte[]> |
| | | { |
| | | |
| | | /** |
| | | * Compare two offsets in an byte array using the DN compare algorithm. |
| | | * The specified index ID is used in the comparision if the byte arrays |
| | | * are equal. |
| | | * |
| | | * @param b The byte array. |
| | | * @param offset The first offset. |
| | | * @param length The first length. |
| | | * @param indexID The first index id. |
| | | * @param otherOffset The second offset. |
| | | * @param otherLength The second length. |
| | | * @param otherIndexID The second index id. |
| | | * @return a negative integer, zero, or a positive integer as the first |
| | | * offset value is less than, equal to, or greater than the second. |
| | | */ |
| | | public int compare(byte[] b, int offset, int length, int indexID, |
| | | int otherOffset, int otherLength, int otherIndexID) |
| | | { |
| | | for (int i = length - 1, j = otherLength - 1; |
| | | i >= 0 && j >= 0; i--, j--) { |
| | | if (b[offset + i] > b[otherOffset + j]) |
| | | { |
| | | return 1; |
| | | } |
| | | else if (b[offset + i] < b[otherOffset + j]) |
| | | { |
| | | return -1; |
| | | } |
| | | } |
| | | //The arrays are equal, make sure they are in the same index since |
| | | //multiple suffixes might have the same key. |
| | | if(length == otherLength) |
| | | { |
| | | if(indexID == otherIndexID) |
| | | { |
| | | return 0; |
| | | } |
| | | else if(indexID > otherIndexID) |
| | | { |
| | | return 1; |
| | | } |
| | | else |
| | | { |
| | | return -1; |
| | | } |
| | | } |
| | | if(length > otherLength) |
| | | { |
| | | return 1; |
| | | } |
| | | else |
| | | { |
| | | return -1; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Compare an offset in an byte array with the specified byte array, |
| | | * using the DN compare algorithm. The specified index ID is used in the |
| | | * comparision if the byte arrays are equal. |
| | | * |
| | | * @param b The byte array. |
| | | * @param offset The first offset. |
| | | * @param length The first length. |
| | | * @param indexID The first index id. |
| | | * @param other The second byte array to compare to. |
| | | * @param otherLength The second object's length. |
| | | * @param otherIndexID The second index id. |
| | | * @return a negative integer, zero, or a positive integer as the first |
| | | * offset value is less than, equal to, or greater than the second |
| | | * byte array. |
| | | */ |
| | | public int compare(byte[] b, int offset, int length, int indexID, |
| | | byte[]other, int otherLength, int otherIndexID) |
| | | { |
| | | for (int i = length - 1, j = otherLength - 1; |
| | | i >= 0 && j >= 0; i--, j--) { |
| | | if (b[offset + i] > other[j]) |
| | | { |
| | | return 1; |
| | | } |
| | | else if (b[offset + i] < other[j]) |
| | | { |
| | | return -1; |
| | | } |
| | | } |
| | | //The arrays are equal, make sure they are in the same index since |
| | | //multiple suffixes might have the same key. |
| | | if(length == otherLength) |
| | | { |
| | | if(indexID == otherIndexID) |
| | | { |
| | | return 0; |
| | | } |
| | | else if(indexID > otherIndexID) |
| | | { |
| | | return 1; |
| | | } |
| | | else |
| | | { |
| | | return -1; |
| | | } |
| | | } |
| | | if(length > otherLength) |
| | | { |
| | | return 1; |
| | | } |
| | | else |
| | | { |
| | | return -1; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Compare an offset in an byte array with the specified byte array, |
| | | * using the DN compare algorithm. |
| | | * |
| | | * @param b The byte array. |
| | | * @param offset The first offset. |
| | | * @param length The first length. |
| | | * @param other The second byte array to compare to. |
| | | * @param otherLength The second object's length. |
| | | * @return a negative integer, zero, or a positive integer as the first |
| | | * offset value is less than, equal to, or greater than the |
| | | * second byte array. |
| | | */ |
| | | public int compare(byte[] b, int offset, int length, byte[] other, |
| | | int otherLength) |
| | | { |
| | | for (int i = length - 1, j = otherLength - 1; |
| | | i >= 0 && j >= 0; i--, j--) { |
| | | if (b[offset + i] > other[j]) |
| | | { |
| | | return 1; |
| | | } |
| | | else if (b[offset + i] < other[j]) |
| | | { |
| | | return -1; |
| | | } |
| | | } |
| | | if(length == otherLength) |
| | | { |
| | | return 0; |
| | | } |
| | | if(length > otherLength) |
| | | { |
| | | return 1; |
| | | } |
| | | else |
| | | { |
| | | return -1; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * Implementation of ComparatorBuffer interface. Used to compare keys when |
| | | * they are non-DN indexes. |
| | | */ |
| | | public static |