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 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()); }
@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 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 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); } }
for (int i = 0; store.getPosition() < len; i++) long latlon = store.readVLong(); if (i == entry)