std-rotate

Tag

Cards List
#std-rotate

Rotation revisited: Avoiding having to calculate the gcd when doing cycle decomposition

The Old New Thing (Raymond Chen) · 2026-06-05 Cached

This article explains a technique to avoid calculating the greatest common divisor when performing cycle decomposition in std::rotate, as used in OpenJDK's Collections.rotate method. It provides a C++ implementation that tracks the count of rotated elements to determine when all cycles are complete.

0 favorites 0 likes
← Back to home

Submit Feedback