RAMDirectory teaches to position the cursor to the end of previous chunk in this case
348939
private void setBufferToCurrentChunkIfPossible() {
      ChunkCacheKey key = new ChunkCacheKey(fileKey.getIndexName(), filename, currentLoadedChunk, chunkSize, affinitySegmentId);
      buffer = (byte[]) chunksCache.get(key);
      if (buffer == null) {
         currentLoadedChunk--;
         bufferPosition = chunkSize;
      }
      else {
         currentBufferSize = buffer.length;
      }
   }
231839
def __get_chunk(self, start=0, end=None):
        '''
        
        '''
        piece = False

        if (self.__filename and os.access(self.__filename, os.R_OK)):

            fhandle = None

            try:
                fhandle = os.open(self.__filename, os.O_RDONLY)
            except OSError:
                print(("Couldn't open file %s" % (self.__filename)))
                fhandle = None

            if (fhandle):

                try:
                    sarmap = mmap.mmap(fhandle, length=0, prot=mmap.PROT_READ)
                except (TypeError, IndexError):
                    os.close(fhandle)
                    traceback.print_exc()
                    #sys.exit(-1)
                    return False

                if (not end):
                    end = sarmap.size()

                try:
                    sarmap.seek(start)
                    piece = sarmap.read(end - start)
                except:
                    traceback.print_exc()

            os.close(fhandle)

        return(piece)
1188811
private static final int previousSpaceIndex(StringBuffer sb, int seek) {
    seek--;
    while (seek > 0) {
      if (sb.charAt(seek) == ' ') {
        while (seek > 0 && sb.charAt(seek - 1) == ' ')
          seek--;
        return seek;
      }
      seek--;
    }
    return 0;
  }
515184
private void checkInUseChunk(long p) {
    if (VALIDATING) {
      checkAnyChunk(p);
      if (!isInUse(p))
        throw new AssertionError("Chunk at " + p + " is not in use");
      if (!nextPreviousInUse(p))
        throw new AssertionError("Chunk after " + p + " does not see this chunk as in use");
      /* If not pinuse previous chunk has OK offset */
      if (!previousInUse(p) && nextChunk(prevChunk(p)) != p)
        throw new AssertionError("Previous chunk to " + p + " is marked free but has an incorrect next pointer");
    }
  }
280095
private void seekToChunkStart()
    {
        if (getOnDiskFilePointer() != chunkOffset)
        {
            try
            {
                out.seek(chunkOffset);
            }
            catch (IOException e)
            {
                throw new FSReadError(e, getPath());
            }
        }
    }
350831
function mkdirSyncRecursive(root, chunks, mode) {

  var chunk = chunks.shift();
  if (!chunk) {
    return;
  }
  var root = path.join(root, chunk);

  if (fs.existsSync(root) === true) { // already done
    return mkdirSyncRecursive(root, chunks, mode);
  }
  var err = fs.mkdirSync(root, mode);
  return err ? err : mkdirSyncRecursive(root, chunks, mode); // let's magic
}
28819
def rewind(self, position=0):
        """"""
        if position < 0 or position > len(self._data):
            raise Exception("Invalid position to rewind cursor to: %s." % position)
        self._position = position
336108
function findFirstOverlappingChunk(chunks, windowStartIndex, windowEndIndex)
{
  var helper = function(chunks,
                        chunkIndexLeft,
                        chunkIndexRight,
                        windowStartIndex,
                        windowEndIndex)
  {
    var result;
    var chunkIndexMiddle;
    var middleChunk;
    var middleChunkEndIndex;

    // initialize the return value to -1
    result = -1;

    // compute the index of the middle chunk and get the middle chunk
    chunkIndexMiddle = Math.floor((chunkIndexLeft + chunkIndexRight) / 2);
    middleChunk = chunks[chunkIndexMiddle];

    // if we have two or fewer chunks
    if ((chunkIndexMiddle === chunkIndexLeft) ||
        (chunkIndexMiddle === chunkIndexRight))
    {
      // if we have just one chunk, and it overlaps with the specified window,
      // we've found the chunk we were looking for
      if (chunkIndexLeft === chunkIndexRight)
      {
        if (middleChunk.overlapsWithWindow(windowStartIndex, windowEndIndex))
        {
          result = chunkIndexLeft;
        }
      }
      else // we just have two chunks left to check
      {
        // if the first chunk overlaps with the specified window, that's the
        // chunk we were looking for
        if (chunks[chunkIndexLeft].overlapsWithWindow(
                windowStartIndex, windowEndIndex))
        {
          result = chunkIndexLeft;
        }

        // otherwise, if the second chunk overlaps with the specified window,
        // that's the chunk we were looking for
        else if (chunks[chunkIndexRight].overlapsWithWindow(
                windowStartIndex, windowEndIndex))
        {
          result = chunkIndexRight;
        }
      }

      return result;
    }

    // if the middle chunk does not overlap with the specified window
    if (!middleChunk.overlapsWithWindow(windowStartIndex, windowEndIndex))
    {
      middleChunkEndIndex = middleChunk.getEndIndex();

      // if the window is to the right of the middle chunk,
      // recurse on the right half
      if (windowStartIndex > middleChunkEndIndex)
      {
        return helper(
            chunks,
            chunkIndexMiddle,
            chunkIndexRight,
            windowStartIndex,
            windowEndIndex);
      }
      else
      {
        // recurse on the left half
        return helper(
            chunks,
            chunkIndexLeft,
            chunkIndexMiddle,
            windowStartIndex,
            windowEndIndex);
      }
    }
    else
    {
      // if the middle chunk overlaps but the chunk before it does not, the
      // middle chunk is the one we were looking
      if ((chunkIndexMiddle === 0) ||
          !chunks[chunkIndexMiddle - 1].overlapsWithWindow(
              windowStartIndex, windowEndIndex))
      {
        return chunkIndexMiddle;
      }
      else
      {
        // recurse on the left half
        return helper(
            chunks,
            chunkIndexLeft,
            chunkIndexMiddle,
            windowStartIndex,
            windowEndIndex);
      }
    }
  };

  return helper(chunks, 0, chunks.length - 1, windowStartIndex, windowEndIndex);
}
195458
def next_chunk(self):
        
        if self._unconsumed:
            data = self._unconsumed.pop()
        else:
            data = self._iterator.next()  # Might raise StopIteration
        self._pos += len(data)
        return data
868897
function (position, iteration, callback, scope) {
        var coords = _.isFunction(callback) && this.current();

        // if null or undefined implies use existing seek position
        _.isNil(position) && (position = this.position);
        _.isNil(iteration) && (iteration = this.iteration);

        // make the pointers stay within boundary
        if ((position >= this.length) || (iteration >= this.cycles) || (position < 0) || (iteration < 0) ||
            isNaN(position) || isNaN(iteration)) {
            return coords &&
                callback.call(scope || this, new Error('runcursor: seeking out of bounds: ' + [position, iteration]));
        }

        // floor the numbers
        position = ~~position;
        iteration = ~~iteration;

        // set the new positions
        this.position = Cursor.validate(position, 0, this.length);
        this.iteration = Cursor.validate(iteration, 0, this.cycles);

        // finally execute the callback with the seek position
        return coords && callback.call(scope || this, null, this.hasChanged(coords), this.current(), coords);
    }
1368472
def rewind(self, places):
        '''
        '''
        log.debug("Rewinding pos %d with %d places" % (self.pos, places))
        self.pos -= places
        log.debug("Reset buffer to pos %d" % self.pos)
484459
def set_cursor_position(self, path, position):
        
        try:
            map = json.loads(self._settings.value('cachedCursorPosition'))
        except TypeError:
            map = {}
        map[path] = position
        self._settings.setValue('cachedCursorPosition', json.dumps(map))
1331002
def _url_chunk_join(self, *args):
        """"""
        # Strip slashes from either side of each path piece.
        pathlets = map(lambda s: s.strip('/'), args)
        # Remove empty pieces.
        pathlets = filter(None, pathlets)
        url = '/'.join(pathlets)
        # If this is a directory, add a trailing slash.
        if args[-1].endswith('/'):
            url = '%s/' % url
        return url
1277064
private int look_for_slash_slash(char[] array, int cursor, int end) {
        while (cursor + 2 <= end) {
            int c = array[cursor++];
            if (c == '/') {
                c = array[cursor++];
                if (c == '/') {
                    return cursor;
                }
            }
        }
        return end;
    }
1069897
def _siftdown_max(heap, startpos, pos):
    ''
    newitem = heap[pos]
    # Follow the path to the root, moving parents down until finding a place
    # newitem fits.
    while pos > startpos:
        parentpos = (pos - 1) >> 1
        parent = heap[parentpos]
        if parent < newitem:
            heap[pos] = parent
            pos = parentpos
            continue
        break
    heap[pos] = newitem
791062
@Override
    public void findNext(String str) {
        int startLine = getLine();
        int startColumn = getColumn();
        highLight(str);
        delegate.findNext(str);
        int targetLine = getLine();
        int targetColumn = getColumn();
        //Rest the actual pointer
        delegate.move(startLine, startColumn);
        int verticalOffset = targetLine - getLine();
        moveVertical(verticalOffset);
        int horizontalOffset = targetColumn - getColumn();
        moveHorizontally(horizontalOffset);
        redrawText();

    }
641519
function memoryAppender(layout, timezoneOffset) {
        layout = layout || layouts.basicLayout;
        return function(loggingEvent) {
            if((buffer.length + 1) > maxBufferSize)
            {
                var numtoRemove = (buffer.length - maxBufferSize) + 1;
                if(numtoRemove > 0){ buffer.splice(0, numtoRemove); }
            }
            buffer.push(layout(loggingEvent, timezoneOffset));
        };
    }