| 1 | |
|
| 2 | |
package org.galagosearch.tupleflow; |
| 3 | |
|
| 4 | |
import java.io.IOException; |
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | |
|
| 22 | |
|
| 23 | |
|
| 24 | 0 | public class Delta { |
| 25 | |
public static void encodeAscending(ArrayOutput output, String current, String last) throws IOException { |
| 26 | 0 | encode(output, current, last); |
| 27 | 0 | } |
| 28 | |
|
| 29 | |
public static void encodeDescending(ArrayOutput output, String current, String last) throws IOException { |
| 30 | 0 | encode(output, current, last); |
| 31 | 0 | } |
| 32 | |
|
| 33 | |
public static void encode(ArrayOutput output, String current, String last) throws IOException { |
| 34 | 0 | int maximum = Math.min(current.length(), last.length()); |
| 35 | |
int i; |
| 36 | |
|
| 37 | 0 | for (i = 0; i < maximum; i++) { |
| 38 | 0 | if (current.charAt(i) != last.charAt(i)) { |
| 39 | 0 | break; |
| 40 | |
} |
| 41 | |
} |
| 42 | |
|
| 43 | 0 | int overlap = i; |
| 44 | |
|
| 45 | 0 | output.writeInt(overlap); |
| 46 | 0 | output.writeString(last.substring(overlap)); |
| 47 | 0 | } |
| 48 | |
|
| 49 | |
public static String decodeAscending(ArrayInput input, String last) throws IOException { |
| 50 | 0 | return decode(input, last); |
| 51 | |
} |
| 52 | |
|
| 53 | |
public static String decodeDescending(ArrayInput input, String last) throws IOException { |
| 54 | 0 | return decode(input, last); |
| 55 | |
} |
| 56 | |
|
| 57 | |
public static String decode(ArrayInput input, String last) throws IOException { |
| 58 | 0 | int overlap = input.readInt(); |
| 59 | 0 | String suffix = input.readString(); |
| 60 | |
|
| 61 | 0 | return last.substring(0, overlap) + suffix; |
| 62 | |
} |
| 63 | |
|
| 64 | |
public static void encodeAscending(ArrayOutput output, long current, long last) throws IOException { |
| 65 | 0 | output.writeLong(current - last); |
| 66 | 0 | } |
| 67 | |
|
| 68 | |
public static void encodeDescending(ArrayOutput output, long current, long last) throws IOException { |
| 69 | 0 | output.writeLong(last - current); |
| 70 | 0 | } |
| 71 | |
|
| 72 | |
public static long decodeAscending(ArrayInput input, long last) throws IOException { |
| 73 | 0 | return last + input.readLong(); |
| 74 | |
} |
| 75 | |
|
| 76 | |
public static int decodeAscending(ArrayInput input, int last) throws IOException { |
| 77 | 0 | return last + input.readInt(); |
| 78 | |
} |
| 79 | |
|
| 80 | |
public static long decodeDescending(ArrayInput input, long last) throws IOException { |
| 81 | 0 | return last - input.readLong(); |
| 82 | |
} |
| 83 | |
|
| 84 | |
public static int decodeDescending(ArrayInput input, int last) throws IOException { |
| 85 | 0 | return last - input.readInt(); |
| 86 | |
} |
| 87 | |
|
| 88 | |
public static String resetString() { |
| 89 | 0 | return ""; |
| 90 | |
} |
| 91 | |
|
| 92 | |
public static int resetInt() { |
| 93 | 0 | return 0; |
| 94 | |
} |
| 95 | |
|
| 96 | |
public static long resetLong() { |
| 97 | 0 | return 0; |
| 98 | |
} |
| 99 | |
} |