Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rotate implementation #1

Open
make-github-pseudonymous-again opened this issue Apr 25, 2015 · 0 comments
Open

rotate implementation #1

make-github-pseudonymous-again opened this issue Apr 25, 2015 · 0 comments
Assignees

Comments

@make-github-pseudonymous-again
Copy link
Member

There is an alternative to the current reverse x 3 approach that is also in place and O(n). This alternative might be more memory access friendly as it only loops on the array once in forward order.

// rotate left version
let rotate = function ( a , i , j , k ) {
    if ( k <= 0 ) return ;
    while ( ( i += k ) + k < j ) swapranges( a , i - k , i , a , i ) ;
    swapranges( a , i , j , a , i - k ) ;
    rotate( a , j - k , j , k - ( j - i ) ) ; // tail recursion
}
@make-github-pseudonymous-again make-github-pseudonymous-again transferred this issue from array-like/experimental Jul 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant