public GHPoint get(long index) { int segmentNo = (int) (index / entriesPerSegment); int entry = (int) (index % entriesPerSegment); try { if (segmentNo >= segments.size()) { return null; } byte[] bytes = segments.get(segmentNo); VLongStorage store = new VLongStorage(decompress(bytes)); long len = store.getLength(); for (int i = 0; store.getPosition() < len; i++) { long latlon = store.readVLong(); if (i == entry) { GHPoint point = new GHPoint(); algo.decode(latlon, point); return point; } } return null; } catch (ArrayIndexOutOfBoundsException ex) { throw new RuntimeException("index " + index + "=> segNo:" + segmentNo + ", entry=" + entry + ", segments:" + segments.size(), ex); } catch (Exception ex) { throw new RuntimeException(ex); } }
@Test public void testWriteWithTrim() { VLongStorage store = new VLongStorage(); store.seek(0); store.writeVLong(1); store.trimToSize(); assertEquals(1, store.getPosition()); store.writeVLong(7); store.trimToSize(); assertEquals(2, store.getPosition()); store.writeVLong(777666555); store.trimToSize(); assertEquals(7, store.getPosition()); store.seek(0); assertEquals(1L, store.readVLong()); assertEquals(7L, store.readVLong()); assertEquals(777666555L, store.readVLong()); } }
public void flush() { if (currentWriter == null) { return; } try { currentWriter.trimToSize(); byte[] input = currentWriter.getBytes(); segments.add(compress(input, 0, input.length, compressionLevel)); currentWriter = null; currentEntry = 0; } catch (Exception ex) { throw new RuntimeException(ex); } }
public void write(double lat, double lon) { try { if (currentWriter == null) currentWriter = new VLongStorage(entriesPerSegment * approxBytesPerEntry); long latlon = algo.encode(new GHPoint(lat, lon)); // we cannot use delta encoding as vlong does not support negative numbers // but compression of vlong is much more efficient than directly storing the integers currentWriter.writeVLong(latlon); currentEntry++; if (currentEntry >= entriesPerSegment) { flush(); } } catch (Exception ex) { throw new RuntimeException(ex); } }
/** * Writes an long in a variable-length format. Writes between one and nine bytes. Smaller values * take fewer bytes. Negative numbers are not supported. * <p> * The format is described further in Lucene its DataOutput#writeVInt(int) * <p> * See DataInput readVLong of Lucene */ public final void writeVLong(long i) { assert i >= 0L; while ((i & ~0x7FL) != 0L) { writeByte((byte) ((i & 0x7FL) | 0x80L)); i >>>= 7; } writeByte((byte) i); }
byte b = readByte(); if (b >= 0) { return b; b = readByte(); i |= (b & 0x7FL) << 7; if (b >= 0) { return i; b = readByte(); i |= (b & 0x7FL) << 14; if (b >= 0) { return i; b = readByte(); i |= (b & 0x7FL) << 21; if (b >= 0) { return i; b = readByte(); i |= (b & 0x7FL) << 28; if (b >= 0) { return i; b = readByte(); i |= (b & 0x7FL) << 35; if (b >= 0) { return i;
@Test public void testWrite() { VLongStorage store = new VLongStorage(); store.seek(0); store.writeVLong(1); store.writeVLong(7); assertEquals(2, store.getPosition()); store.writeVLong(777666555); assertEquals(7, store.getPosition()); store.seek(0); assertEquals(1L, store.readVLong()); assertEquals(7L, store.readVLong()); assertEquals(777666555L, store.readVLong()); }
public void write(double lat, double lon) { try { if (currentWriter == null) currentWriter = new VLongStorage(entriesPerSegment * approxBytesPerEntry); long latlon = algo.encode(new GHPoint(lat, lon)); // we cannot use delta encoding as vlong does not support negative numbers // but compression of vlong is much more efficient than directly storing the integers currentWriter.writeVLong(latlon); currentEntry++; if (currentEntry >= entriesPerSegment) { flush(); } } catch (Exception ex) { throw new RuntimeException(ex); } }
/** * Writes an long in a variable-length format. Writes between one and nine bytes. Smaller values * take fewer bytes. Negative numbers are not supported. * <p> * The format is described further in Lucene its DataOutput#writeVInt(int) * <p> * See DataInput readVLong of Lucene */ public final void writeVLong(long i) { assert i >= 0L; while ((i & ~0x7FL) != 0L) { writeByte((byte) ((i & 0x7FL) | 0x80L)); i >>>= 7; } writeByte((byte) i); }
byte b = readByte(); if (b >= 0) { return b; b = readByte(); i |= (b & 0x7FL) << 7; if (b >= 0) { return i; b = readByte(); i |= (b & 0x7FL) << 14; if (b >= 0) { return i; b = readByte(); i |= (b & 0x7FL) << 21; if (b >= 0) { return i; b = readByte(); i |= (b & 0x7FL) << 28; if (b >= 0) { return i; b = readByte(); i |= (b & 0x7FL) << 35; if (b >= 0) { return i;
public GHPoint get(long index) { int segmentNo = (int) (index / entriesPerSegment); int entry = (int) (index % entriesPerSegment); try { if (segmentNo >= segments.size()) { return null; } byte[] bytes = segments.get(segmentNo); VLongStorage store = new VLongStorage(decompress(bytes)); long len = store.getLength(); for (int i = 0; store.getPosition() < len; i++) { long latlon = store.readVLong(); if (i == entry) { GHPoint point = new GHPoint(); algo.decode(latlon, point); return point; } } return null; } catch (ArrayIndexOutOfBoundsException ex) { throw new RuntimeException("index " + index + "=> segNo:" + segmentNo + ", entry=" + entry + ", segments:" + segments.size(), ex); } catch (Exception ex) { throw new RuntimeException(ex); } }
public void write(double lat, double lon) { try { if (currentWriter == null) currentWriter = new VLongStorage(entriesPerSegment * approxBytesPerEntry); long latlon = algo.encode(new GHPoint(lat, lon)); // we cannot use delta encoding as vlong does not support negative numbers // but compression of vlong is much more efficient than directly storing the integers currentWriter.writeVLong(latlon); currentEntry++; if (currentEntry >= entriesPerSegment) { flush(); } } catch (Exception ex) { throw new RuntimeException(ex); } }
public void flush() { if (currentWriter == null) { return; } try { currentWriter.trimToSize(); byte[] input = currentWriter.getBytes(); segments.add(compress(input, 0, input.length, compressionLevel)); currentWriter = null; currentEntry = 0; } catch (Exception ex) { throw new RuntimeException(ex); } }
/** * Writes an long in a variable-length format. Writes between one and nine bytes. Smaller values * take fewer bytes. Negative numbers are not supported. * <p> * The format is described further in Lucene its DataOutput#writeVInt(int) * <p> * See DataInput readVLong of Lucene */ public final void writeVLong(long i) { assert i >= 0L; while ((i & ~0x7FL) != 0L) { writeByte((byte) ((i & 0x7FL) | 0x80L)); i >>>= 7; } writeByte((byte) i); }
byte b = readByte(); if (b >= 0) b = readByte(); i |= (b & 0x7FL) << 7; if (b >= 0) b = readByte(); i |= (b & 0x7FL) << 14; if (b >= 0) b = readByte(); i |= (b & 0x7FL) << 21; if (b >= 0) b = readByte(); i |= (b & 0x7FL) << 28; if (b >= 0) b = readByte(); i |= (b & 0x7FL) << 35; if (b >= 0) b = readByte(); i |= (b & 0x7FL) << 42; if (b >= 0) b = readByte(); i |= (b & 0x7FL) << 49;
public GHPoint get(long index) { int segmentNo = (int) (index / entriesPerSegment); int entry = (int) (index % entriesPerSegment); try { if (segmentNo >= segments.size()) { return null; } byte[] bytes = segments.get(segmentNo); VLongStorage store = new VLongStorage(decompress(bytes)); long len = store.getLength(); for (int i = 0; store.getPosition() < len; i++) { long latlon = store.readVLong(); if (i == entry) { GHPoint point = new GHPoint(); algo.decode(latlon, point); return point; } } return null; } catch (ArrayIndexOutOfBoundsException ex) { throw new RuntimeException("index " + index + "=> segNo:" + segmentNo + ", entry=" + entry + ", segments:" + segments.size(), ex); } catch (Exception ex) { throw new RuntimeException(ex); } }
public void write( double lat, double lon ) { try { if (currentWriter == null) currentWriter = new VLongStorage(entriesPerSegment * approxBytesPerEntry); long latlon = algo.encode(new GHPoint(lat, lon)); // we cannot use delta encoding as vlong does not support negative numbers // but compression of vlong is much more efficient than directly storing the integers currentWriter.writeVLong(latlon); currentEntry++; if (currentEntry >= entriesPerSegment) { flush(); } } catch (Exception ex) { throw new RuntimeException(ex); } }
public void flush() { if (currentWriter == null) { return; } try { currentWriter.trimToSize(); byte[] input = currentWriter.getBytes(); segments.add(compress(input, 0, input.length, compressionLevel)); currentWriter = null; currentEntry = 0; } catch (Exception ex) { throw new RuntimeException(ex); } }
/** * Writes an long in a variable-length format. Writes between one and nine bytes. Smaller values * take fewer bytes. Negative numbers are not supported. * <p> * The format is described further in Lucene its DataOutput#writeVInt(int) * <p> * See DataInput readVLong of Lucene */ public final void writeVLong( long i ) { assert i >= 0L; while ((i & ~0x7FL) != 0L) { writeByte((byte) ((i & 0x7FL) | 0x80L)); i >>>= 7; } writeByte((byte) i); }
byte b = readByte(); if (b >= 0) { return b; b = readByte(); i |= (b & 0x7FL) << 7; if (b >= 0) { return i; b = readByte(); i |= (b & 0x7FL) << 14; if (b >= 0) { return i; b = readByte(); i |= (b & 0x7FL) << 21; if (b >= 0) { return i; b = readByte(); i |= (b & 0x7FL) << 28; if (b >= 0) { return i; b = readByte(); i |= (b & 0x7FL) << 35; if (b >= 0) { return i;