Software /
code /
prosody
Changeset
4423:ded726418b16
util.rfc3484: Use a stable sorting algorithm
author | Florian Zeitz <florob@babelmonkeys.de> |
---|---|
date | Sun, 06 Nov 2011 18:23:16 +0100 |
parents | 4422:c25dee24623f |
children | 4428:0317b01b6bcd |
files | util/rfc3484.lua |
diffstat | 1 files changed, 11 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/util/rfc3484.lua Wed Oct 26 02:03:33 2011 +0200 +++ b/util/rfc3484.lua Sun Nov 06 18:23:16 2011 +0100 @@ -5,10 +5,20 @@ -- COPYING file in the source package for more information. -- -local t_sort = table.sort; local commonPrefixLength = require"util.ip".commonPrefixLength local new_ip = require"util.ip".new_ip; +local function t_sort(t, comp) + for i = 1, (#t - 1) do + for j = (i + 1), #t do + local a, b = t[i], t[j]; + if not comp(a,b) then + t[i], t[j] = b, a; + end + end + end +end + function source(dest, candidates) local function comp(ipA, ipB) -- Rule 1: Prefer same address @@ -61,7 +71,6 @@ end function destination(candidates, sources) - local t_sort = table.sort; local sourceAddrs = {}; local function comp(ipA, ipB) local ipAsource = sourceAddrs[ipA];