parameters: (key, list_, base, length, hint, comparefn)
return_statement: return offset
docstring: Like gallop_left, except that if the range contains an element equal to
  	key, gallop_right returns the index after the rightmost equal element.
  	
  	@param key the key whose insertion point to search for
  	@param list_ the array in which to search
  	@param base the index of the first element in the range
  	@param length the length of the range; must be > 0
  	@param hint the index at which to begin the search, 0 <= hint < number.
  	 The closer hint is to the result, the faster this method will run.
  	@param comparefn the comparator used to order the range, and to search
  	@return the int k,  0 <= k <= number such that list_[b + k - 1] <= key < list_[b + k]
docstring_summary: Like gallop_left, except that if the range contains an element equal to
  	key, gallop_right returns the index after the rightmost equal element.
docstring_tokens: Like gallop_left except that if the range contains an element equal to key gallop_right returns the index after the rightmost equal element .
function: def gallop_right(key, list_, base, length, hint, comparefn):
  	# pylint: disable=R0913
  	# R0913: We need a lot of arguments, at least for now
  	'''
  	Like gallop_left, except that if the range contains an element equal to
  	key, gallop_right returns the index after the rightmost equal element.
  	
  	@param key the key whose insertion point to search for
  	@param list_ the array in which to search
  	@param base the index of the first element in the range
  	@param length the length of the range; must be > 0
  	@param hint the index at which to begin the search, 0 <= hint < number.
  	 The closer hint is to the result, the faster this method will run.
  	@param comparefn the comparator used to order the range, and to search
  	@return the int k,  0 <= k <= number such that list_[b + k - 1] <= key < list_[b + k]
  	'''
  	assert length > 0 and hint >= 0 and hint < length
  
  	offset = 1
  	last_offset = 0
  	if comparefn(key, list_[base + hint]) < 0:
  		# Gallop left until list_[b+hint - offset] <= key < list_[b+hint - last_offset]
  		max_offset = hint + 1
  		while offset < max_offset and comparefn(key, list_[base + hint - offset]) < 0:
  			last_offset = offset
  			offset = (offset << 1) + 1
  			if offset <= 0:
  				# int overflow
  				offset = max_offset
  		if offset > max_offset:
  			offset = max_offset
  
  		# Make offsets relative to b
  		tmp = last_offset
  		last_offset = hint - offset
  		offset = hint - tmp
  	else:
  		# list_[b + hint] <= key
  		# Gallop right until list_[b+hint + last_offset] <= key < list_[b+hint + offset]
  		max_offset = length - hint
  		while offset < max_offset and comparefn(key, list_[base + hint + offset]) >= 0:
  			last_offset = offset
  			offset = (offset << 1) + 1
  			if offset <= 0:
  				# int overflow
  				offset = max_offset
  		if offset > max_offset:
  			offset = max_offset
  
  		# Make offsets relative to b
  		last_offset += hint
  		offset += hint
  	assert -1 <= last_offset and last_offset < offset and offset <= length
  
  	#
  	# Now list_[b + last_offset] <= key < list_[b + offset], so key belongs somewhere to
  	# the right of last_offset but no farther right than offset.  Do a binary
  	# search, with invariant list_[b + last_offset - 1] <= key < list_[b + offset].
  	#
  	last_offset += 1
  	while last_offset < offset:
  		midpoint = last_offset + ((offset - last_offset) / 2)
  
  		if comparefn(key, list_[base + midpoint]) < 0:
  			# key < list_[b + midpoint]
  			offset = midpoint
  		else:
  			# list_[b + midpoint] <= key
  			last_offset = midpoint + 1
  	# so list_[b + offset - 1] <= key < list_[b + offset]
  	assert last_offset == offset
  	return offset
function_tokens: def gallop_right ( key , list_ , base , length , hint , comparefn ) : # pylint: disable=R0913 # R0913: We need a lot of arguments, at least for now assert length > 0 and hint >= 0 and hint < length offset = 1 last_offset = 0 if comparefn ( key , list_ [ base + hint ] ) < 0 : # Gallop left until list_[b+hint - offset] <= key < list_[b+hint - last_offset] max_offset = hint + 1 while offset < max_offset and comparefn ( key , list_ [ base + hint - offset ] ) < 0 : last_offset = offset offset = ( offset << 1 ) + 1 if offset <= 0 : # int overflow offset = max_offset if offset > max_offset : offset = max_offset # Make offsets relative to b tmp = last_offset last_offset = hint - offset offset = hint - tmp else : # list_[b + hint] <= key # Gallop right until list_[b+hint + last_offset] <= key < list_[b+hint + offset] max_offset = length - hint while offset < max_offset and comparefn ( key , list_ [ base + hint + offset ] ) >= 0 : last_offset = offset offset = ( offset << 1 ) + 1 if offset <= 0 : # int overflow offset = max_offset if offset > max_offset : offset = max_offset # Make offsets relative to b last_offset += hint offset += hint assert - 1 <= last_offset and last_offset < offset and offset <= length # # Now list_[b + last_offset] <= key < list_[b + offset], so key belongs somewhere to # the right of last_offset but no farther right than offset.  Do a binary # search, with invariant list_[b + last_offset - 1] <= key < list_[b + offset]. # last_offset += 1 while last_offset < offset : midpoint = last_offset + ( ( offset - last_offset ) / 2 ) if comparefn ( key , list_ [ base + midpoint ] ) < 0 : # key < list_[b + midpoint] offset = midpoint else : # list_[b + midpoint] <= key last_offset = midpoint + 1 # so list_[b + offset - 1] <= key < list_[b + offset] assert last_offset == offset return offset