def advance_wrap(self, steps):
assert self.is_valid()
if steps == 0:
return self
step_shift = 2 * (self.__class__.MAX_LEVEL - self.level()) + 1
if steps < 0:
min_steps = -(self.id() >> step_shift)
if steps < min_steps:
step_wrap = self.__class__.WRAP_OFFSET >> step_shift
# cannot use steps %= step_wrap as Python % different to C++
steps = int(math.fmod(steps, step_wrap))
if steps < min_steps:
steps += step_wrap
else:
max_steps = (self.__class__.WRAP_OFFSET - self.id()) >> step_shift
if steps > max_steps:
step_wrap = self.__class__.WRAP_OFFSET >> step_shift
# cannot use steps %= step_wrap as Python % different to C++
steps = int(math.fmod(steps, step_wrap))
if steps > max_steps:
steps -= step_wrap
return self.__class__(self.id() + (steps << step_shift))
评论列表
文章目录