A
Andrew Savige
The following program is a simple example of sorting positive integers
using the Guttman-Rosler transform:
print map { substr($_, 4) } sort map { pack('N', $_) . $_ } <DATA>;
__END__
2
256
255
32000
33000
12345678
12345679
1234567
1
It seems to me that pack('N', $_) is sound while pack('L', $_) is
unsound (because 'N' is guaranteed big-endian, while 'L' is not).
Is that right?
What is the recommended way to do a descending numeric sort?
Changing pack('N', $_) to pack('N', -$_) seems to work.
Is it sound?
If the data contains negative integers, the simple program above
does not work. What is the recommended technique in that case?
Changing pack('N', $_) to pack('N', $_ ^ (1 << 31)) seems to work.
Is it sound?
/-\
using the Guttman-Rosler transform:
print map { substr($_, 4) } sort map { pack('N', $_) . $_ } <DATA>;
__END__
2
256
255
32000
33000
12345678
12345679
1234567
1
It seems to me that pack('N', $_) is sound while pack('L', $_) is
unsound (because 'N' is guaranteed big-endian, while 'L' is not).
Is that right?
What is the recommended way to do a descending numeric sort?
Changing pack('N', $_) to pack('N', -$_) seems to work.
Is it sound?
If the data contains negative integers, the simple program above
does not work. What is the recommended technique in that case?
Changing pack('N', $_) to pack('N', $_ ^ (1 << 31)) seems to work.
Is it sound?
/-\