Re: Slice sequence--new algorithm

new topic     » goto parent     » topic index » view thread      » older message » newer message

Lutz, Al & co,

I think the routines below for removal of all occurrences of an
element from a sequence are both simpler and slightly faster than the
ones proposed so far.

jiri


function remove(sequence s, integer n)
    integer p

    p = 0
    for i = 1 to length(s) do
        if s[i] != n then
            p += 1
            s[p] = s[i]
        end if
    end for
    return  s[1..p]
end function

-- generalized:
function remove(sequence s, object n)
    integer p

    p = 0
    for i = 1 to length(s) do
        if compare(s[i], n) then
            p += 1
            s[p] = s[i]
        end if
    end for
    return  s[1..p]
end function

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu