<commit_before>class Innodb::Page
  class Cursor
    attr_reader :offset

    def initialize(page, offset)
      @page = page
      @cursor = offset
      @direction = :forward
    end

    def forward
      @direction = :forward
      self
    end

    def backward
      @direction = :backward
      self
    end

    def seek(offset)
      @cursor = offset if offset
      @cursor
    end

    def adjust(relative_offset)
      @cursor += relative_offset
      @cursor
    end

    def read_and_advance(length, type=nil)
      data = nil
      case @direction
      when :forward
        data = @page.data(@cursor, length)
        adjust(length)
      when :backward
        adjust(-length)
        data = @page.data(@cursor, length)
      end
      type ? data.unpack(type).first : data
    end

    def get_uint8(offset=nil)
      seek(offset)
      read_and_advance(1, "C")
    end

    def get_uint16(offset=nil)
      seek(offset)
      read_and_advance(2, "n")
    end

    def get_sint16(offset=nil)
      seek(offset)
      uint = read_and_advance(2, "n")
      (uint & 32768) == 0 ? uint : -(uint ^ 65535) - 1
    end
  
    def get_uint32(offset=nil)
      seek(offset)
      read_and_advance(4, "N")
    end
  
    def get_uint64(offset=nil)
      seek(offset)
      read_and_advance(8, "Q")
    end

    def get_bytes(length)
      read_and_advance(length)
    end
  end
end<commit_msg>Fix get_uint64 to be big-endian<commit_after>class Innodb::Page
  class Cursor
    attr_reader :offset

    def initialize(page, offset)
      @page = page
      @cursor = offset
      @direction = :forward
    end

    def forward
      @direction = :forward
      self
    end

    def backward
      @direction = :backward
      self
    end

    def seek(offset)
      @cursor = offset if offset
      @cursor
    end

    def adjust(relative_offset)
      @cursor += relative_offset
      @cursor
    end

    def read_and_advance(length, type=nil)
      data = nil
      case @direction
      when :forward
        data = @page.data(@cursor, length)
        adjust(length)
      when :backward
        adjust(-length)
        data = @page.data(@cursor, length)
      end
      type ? data.unpack(type).first : data
    end

    def get_bytes(length)
      read_and_advance(length)
    end

    def get_uint8(offset=nil)
      seek(offset)
      read_and_advance(1, "C")
    end

    def get_uint16(offset=nil)
      seek(offset)
      read_and_advance(2, "n")
    end

    def get_sint16(offset=nil)
      seek(offset)
      uint = read_and_advance(2, "n")
      (uint & 32768) == 0 ? uint : -(uint ^ 65535) - 1
    end
  
    def get_uint32(offset=nil)
      seek(offset)
      read_and_advance(4, "N")
    end
  
    def get_uint64(offset=nil)
      seek(offset)
      # Ruby 1.8 doesn't support big-endian quad-word unpack; unpack as two
      # 32-bit big-endian instead.
      high, low = read_and_advance(8).unpack("NN")
      (high << 32) | low
    end
  end
end
{'fraction_non_alphanumeric': 0.0961021505376344, 'fraction_numerical': 0.020161290322580645, 'mean_word_length': 2.0533333333333332, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3187831', 'n_tokens_mistral': 1047, 'n_tokens_neox': 985, 'n_words': 240}