Skip to content

Instantly share code, notes, and snippets.

@amitjamadagni
Last active August 29, 2015 14:13
Attempt at implementation of ror
function ror!(dest::BitVector, src::BitVector, i::Integer)
n = length(dest)
i %= n
i == 0 && return dest
if src !== dest
copy_chunks!(dest.chunks, i+1, src.chunks, 1, n-i)
copy_chunks!(dest.chunks, 1, src.chunks, n-i+1, i)
return dest
else
Bc = copy(src)
copy_chunks!(src.chunks, i+1, Bc.chunks, 1, n-i)
copy_chunks!(src.chunks, 1, Bc.chunks, n-i+1, i)
return src
end
end
function ror!(B::BitVector, i::Integer)
return ror!(B, B, i)
end
function ror(B::BitVector, i::Integer)
return ror!(similar(B), B, i)
end
#edge-case failure if B is all false in the case of ror.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment