def sort! # rubocop:disable Metrics/AbcSize
      # TODO: Simply the code
      assert_ordered :sort

      # Build sorted index
      old_index = @index.to_a
      new_index = @cat_hash.values.map do |positions|
        old_index.values_at(*positions)
      end.flatten
      @index = @index.class.new new_index

      # Build sorted data
      @cat_hash = categories.inject([{}, 0]) do |acc, cat|
        hash, count = acc
        cat_count = @cat_hash[cat].size
        cat_count.times { |i| @array[count+i] = int_from_cat(cat) }
        hash[cat] = (count...(cat_count+count)).to_a
        [hash, count + cat_count]
      end.first

      self
    end
Sorts the vector in the order specified.
@note This operation will only work if vector is ordered.
To set the vector ordered, do `vector.ordered = true`
@return [Daru::Vector] sorted vector
@example
dv = Daru::Vector.new ['second', 'second', 'third', 'first'],
categories: ['first', 'second', 'thrid'],
type: :categories,
ordered: true
dv.sort!
# => #<Daru::Vector(4)>
#       3  first
#       0 second
#       1 second
#       2  third