I appreciate any insight anyone has to offer on this code. I obviously
don't care about losing NESL's parallel computing power. I am more
interested in a relatively efficient and readable function (or functions)
as the C code I currently have is garbage to read and I don't have the time
to spare to re-write it. I'm too much of a tinkerer when it comes to
Haskell (still looking for the "right" book). And yes, I have tried to
work it into Haskell myself, with rather pointless results. =)
I was going to send the 120k PDF document to the appropriate individuals
(only!) but I figured that IEEE would lambaste me spreading their
information for free. So instead, I post for your "pleasure" the provided
NESL source functions. Pardon my idiocy in converting this code (properly)
myself. =)
function Next-DeBruijn(w, i, k) =
let
C = xor_iscan(w); � � apply (inclusive) prefix scan
Cbar = {1 - a : a in C}; � � compute the bit-complement of the sequence
part1 = take (C, i - k); � � take the first i - k bits from C
part2 = drop (Cbar, i - 1 + k); � � drop the first i - 1 + k bits from
Cbar
part3 = take (Cbar, i - 1 + k); � � take the first i - 1 + k bits from
Cbar
part4 = drop (C, i - k); � � drop the first i - k bits from C in
- - part1 ++ part2 ++ part3 ++ part4� � concatenate the list for output
function Generate-DeBruijn (n, x) =
if (n == 2) then [1,1,0,0]
else if (n == 3) then
if (x [0] == 0) then [1,0,1,1,1,0,0,0]
else [1,1,1,0,1,0,0,0]
else Next-DeBruijn (Generate-DeBruijn(n-1,x), 2 ^ (n-2) + (-1) ^
(x[n-4]), x[n-3]);
Many thanks,
Wayne