2020-11-24 15:15:51 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module RelativePositioning
|
|
|
|
STEPS = 10
|
|
|
|
IDEAL_DISTANCE = 2**(STEPS - 1) + 1
|
|
|
|
|
|
|
|
MIN_POSITION = Gitlab::Database::MIN_INT_VALUE
|
|
|
|
START_POSITION = 0
|
|
|
|
MAX_POSITION = Gitlab::Database::MAX_INT_VALUE
|
|
|
|
|
|
|
|
MAX_GAP = IDEAL_DISTANCE * 2
|
|
|
|
MIN_GAP = 2
|
|
|
|
|
|
|
|
NoSpaceLeft = Class.new(StandardError)
|
2021-06-08 01:23:25 +05:30
|
|
|
InvalidPosition = Class.new(StandardError)
|
2021-03-11 19:13:27 +05:30
|
|
|
IllegalRange = Class.new(ArgumentError)
|
2021-06-08 01:23:25 +05:30
|
|
|
IssuePositioningDisabled = Class.new(StandardError)
|
2021-03-11 19:13:27 +05:30
|
|
|
|
|
|
|
def self.range(lhs, rhs)
|
|
|
|
if lhs && rhs
|
|
|
|
ClosedRange.new(lhs, rhs)
|
|
|
|
elsif lhs
|
|
|
|
StartingFrom.new(lhs)
|
|
|
|
elsif rhs
|
|
|
|
EndingAt.new(rhs)
|
|
|
|
else
|
|
|
|
raise IllegalRange, 'One of rhs or lhs must be provided' unless lhs && rhs
|
|
|
|
end
|
|
|
|
end
|
2020-11-24 15:15:51 +05:30
|
|
|
end
|
|
|
|
end
|