heapsort.mlton

Stephen Weeks MLton@sourcelight.com
Wed, 20 Jun 2001 09:39:47 -0700


--FWTUvPiIzW
Content-Type: text/plain; charset=us-ascii
Content-Description: message body text
Content-Transfer-Encoding: 7bit


Here is a new version, which although not significantly faster, is more
idiomatic SML.



--FWTUvPiIzW
Content-Type: application/octet-stream
Content-Disposition: attachment;
	filename="heapsort.mlton"
Content-Transfer-Encoding: base64

KCogLSotIG1vZGU6IHNtbCAtKi0KICogJElkOiBoZWFwc29ydC5tbHRvbix2IDEuMSAyMDAxLzA2
LzAxIDE3OjU5OjEyIGRvdWcgRXhwICQKICogaHR0cDovL3d3dy5iYWdsZXkub3JnL35kb3VnL3No
b290b3V0LwogKiBCYXNlZCBvbiBoZWFwc29ydC5vY2FtbCBieSBTdGVwaGVuIFdlZWtzLCBpbXBy
b3ZlZCBieSBIZW5yeSBDZWp0aW4uCiopCgp2YWwgc3ViID0gQXJyYXkuc3ViCnZhbCB1cGRhdGUg
PSBBcnJheS51cGRhdGUKICAgCmxvY2FsCiAgIHZhbCBpbSA9IDEzOTk2OAogICB2YWwgaWEgPSAg
IDM4NzcKICAgdmFsIGljID0gIDI5NTczCiAgIHZhbCBsYXN0ID0gcmVmIDQyCiAgIHZhbCBzY2Fs
ZSA9IDEuMCAvIFJlYWwuZnJvbUludCBpbQppbgogICBmdW4gZ2VuX3JhbmRvbSBtYXggPQoJICBs
ZXQgdmFsIGxhc3QnID0gKCEgbGFzdCAqIGlhICsgaWMpIG1vZCBpbQoJICBpbiBsYXN0IDo9IGxh
c3QnOwoJICAgICBtYXggKiBzY2FsZSAqIFJlYWwuZnJvbUludCBsYXN0JwoJICBlbmQKZW5kCgpm
dW4gaGVhcFNvcnQgKG4sIHJhOiByZWFsIGFycmF5KSA9CiAgICAgICBsZXQgZnVuIGlubmVyIChs
LCBpciwgcnJhKSA9CiAgICAgICAgICAgICAgICAgIGxldCBmdW4gbG9vcCAoaSwgaikgPQogICAg
ICAgICAgICAgICAgICAgICAgICAgICAgIGlmIGogPD0gaXIKICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICB0aGVuIGxldCB2YWwgaiA9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgIGlmIGogPCBpcgogICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICBhbmRhbHNvIHN1YiAocmEsIGopIDwgc3ViIChyYSwgaiArIDEp
CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHRoZW4g
aiArIDEKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ZWxzZSBqCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgdmFsIChpLCBq
KSA9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIHJy
YSA8IHN1YiAocmEsIGopCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgICAgICAgIHRoZW4gKHVwZGF0ZSAocmEsIGksIHN1YiAocmEsIGopKTsKICAgICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgKGosIGogKyBqKSkK
ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZWxzZSAo
aSwgaXIgKyAxKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaW4gbG9vcCAo
aSwgaikKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGVuZAogICAgICAgICAg
ICAgICAgICAgICAgICAgICAgICAgIGVsc2UgdXBkYXRlIChyYSwgaSwgcnJhKQogICAgICAgICAg
ICAgICAgICBpbiBsb29wIChsLCBsICsgbCkKICAgICAgICAgICAgICAgICAgZW5kCiAgICAgICAg
ICAgZnVuIG91dGVyMSBsID0KICAgICAgICAgICAgICAgICAgbGV0IHZhbCBsJyA9IGwgLSAxCiAg
ICAgICAgICAgICAgICAgIGluIGlmIGwnID4gMAogICAgICAgICAgICAgICAgICAgICAgICB0aGVu
IChpbm5lciAobCcsIG4sIHN1YiAocmEsIGwnKSk7CiAgICAgICAgICAgICAgICAgICAgICAgICAg
ICAgIG91dGVyMSBsJykKICAgICAgICAgICAgICAgICAgICAgICAgZWxzZSAoKQogICAgICAgICAg
ICAgICAgICBlbmQKICAgICAgICAgICBmdW4gb3V0ZXIyIGlyID0KICAgICAgICAgICAgICAgICAg
bGV0IHZhbCBycmEgPSBzdWIgKHJhLCBpcikKICAgICAgICAgICAgICAgICAgICAgIHZhbCBfID0g
dXBkYXRlIChyYSwgaXIsIHN1YiAocmEsIDEpKQogICAgICAgICAgICAgICAgICAgICAgdmFsIGly
ID0gaXIgLSAxCiAgICAgICAgICAgICAgICAgIGluIGlmIGlyID0gMQogICAgICAgICAgICAgICAg
ICAgICAgICB0aGVuIHVwZGF0ZSAocmEsIDEsIHJyYSkKICAgICAgICAgICAgICAgICAgICAgICAg
ZWxzZSAoaW5uZXIgKDEsIGlyLCBycmEpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICBv
dXRlcjIgaXIpCiAgICAgICAgICAgICAgICAgIGVuZAogICAgICAgaW4gb3V0ZXIxIChuIGRpdiAy
ICsgMSk7CiAgICAgICAgICBvdXRlcjIgbgogICAgICAgZW5kCgpmdW4gYXRvaSBzID0gY2FzZSBJ
bnQuZnJvbVN0cmluZyBzIG9mIFNPTUUgbnVtID0+IG51bSB8IE5PTkUgPT4gMDsKZnVuIHByaW50
bCBbXSA9IHByaW50ICJcbiIgfCBwcmludGwoaDo6dCkgPSAoIHByaW50IGggOyBwcmludGwgdCAp
OwoKZnVuIG1haW4gKG5hbWUsIGFyZ3MpID0KICAgICAgIGxldCB2YWwgbiA9IGF0b2kgKGhkIChh
cmdzIEAgWyIxIl0pKQoJICAgdmFsIGFyeSA9IEFycmF5LnRhYnVsYXRlIChuICsgMSwgZm4gXyA9
PiBnZW5fcmFuZG9tIDEuMCkKICAgICAgIGluIGhlYXBTb3J0IChuLCBhcnkpOwoJICBwcmludCAo
Y29uY2F0IFtSZWFsLmZtdCAoU3RyaW5nQ3Z0LkZJWCAoU09NRSAxMCkpIChzdWIgKGFyeSwgbikp
LAoJCQkgIlxuIl0pCiAgICAgICBlbmQKCnZhbCBfID0gbWFpbiggQ29tbWFuZExpbmUubmFtZSgp
LCBDb21tYW5kTGluZS5hcmd1bWVudHMoKSApCg==

--FWTUvPiIzW--