2
0
mirror of https://github.com/boostorg/build.git synced 2026-02-13 12:22:17 +00:00

optimized insertion-sort

[SVN r18225]
This commit is contained in:
Dave Abrahams
2003-04-10 11:33:13 +00:00
parent 41e33cd9f0
commit 4fae733892

View File

@@ -59,17 +59,36 @@ rule insertion-sort ( s * : ordered * )
local caller = [ CALLER_MODULE ] ;
ordered ?= sequence.less ;
local result = $(s[1]) ;
for local x in $(s[2-])
if $(ordered) = sequence.less
{
local head tail ;
tail = $(result) ;
while $(tail) && [ modules.call-in $(caller) : $(ordered) $(tail[1]) $(x) ]
for local x in $(s[2-])
{
head += $(tail[1]) ;
tail = $(tail[2-]) ;
head = ;
tail = $(result) ;
while $(tail) && ( $(tail[1]) < $(x) )
{
head += $(tail[1]) ;
tail = $(tail[2-]) ;
}
result = $(head) $(x) $(tail) ;
}
result = $(head) $(x) $(tail) ;
}
else
{
for local x in $(s[2-])
{
local head tail ;
tail = $(result) ;
while $(tail) && [ modules.call-in $(caller) : $(ordered) $(tail[1]) $(x) ]
{
head += $(tail[1]) ;
tail = $(tail[2-]) ;
}
result = $(head) $(x) $(tail) ;
}
}
return $(result) ;
}