Skip to content

Commit

Permalink
reorder methods
Browse files Browse the repository at this point in the history
  • Loading branch information
GarrisonJ committed Apr 29, 2024
1 parent 99ab784 commit 1cd65e7
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions lib/sorted_containers/sorted_array.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,37 +70,6 @@ def -(other)
new_instance
end

# rubocop:disable Metrics/MethodLength

# Adds a value to the sorted array.
#
# @param value [Object] The value to add.
def add(value)
if @maxes.empty?
@lists.append([value])
@maxes.append(value)
else
pos = internal_bisect_right(@maxes, value)

if pos == @maxes.size
pos -= 1
@lists[pos].push(value)
@maxes[pos] = value
else
sub_pos = internal_bisect_right(@lists[pos], value)
@lists[pos].insert(sub_pos, value)
end
expand(pos)
end
@size += 1
self
end
alias << add
alias push add
alias append add

# rubocop:enable Metrics/MethodLength

# Returns -1, 0, or 1 as self is less than, equal to, or greater than other. For each index i in self,
# evaluates self[i] <=> other[i]
#
Expand Down Expand Up @@ -213,6 +182,37 @@ def any?
false
end

# rubocop:disable Metrics/MethodLength

# Adds a value to the sorted array.
#
# @param value [Object] The value to add.
def add(value)
if @maxes.empty?
@lists.append([value])
@maxes.append(value)
else
pos = internal_bisect_right(@maxes, value)

if pos == @maxes.size
pos -= 1
@lists[pos].push(value)
@maxes[pos] = value
else
sub_pos = internal_bisect_right(@lists[pos], value)
@lists[pos].insert(sub_pos, value)
end
expand(pos)
end
@size += 1
self
end
alias << add
alias push add
alias append add

# rubocop:enable Metrics/MethodLength

# Returns a string representation of the sorted array.
#
# @return [String] A string representation of the sorted array.
Expand Down

0 comments on commit 1cd65e7

Please sign in to comment.