diff options
author | Florian Zeitz <florob@babelmonkeys.de> | 2011-11-06 18:23:16 +0100 |
---|---|---|
committer | Florian Zeitz <florob@babelmonkeys.de> | 2011-11-06 18:23:16 +0100 |
commit | 278e867c8cae8147a1d83566a4a684d5558ba541 (patch) | |
tree | 1f8124e620c1427d68125444e61aeebc72a05aba | |
parent | a71b4036179108e3de89a8859f1e2d90f4407451 (diff) | |
download | prosody-278e867c8cae8147a1d83566a4a684d5558ba541.tar.gz prosody-278e867c8cae8147a1d83566a4a684d5558ba541.zip |
util.rfc3484: Use a stable sorting algorithm
-rw-r--r-- | util/rfc3484.lua | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/util/rfc3484.lua b/util/rfc3484.lua index 373d3c33..dd855a84 100644 --- a/util/rfc3484.lua +++ b/util/rfc3484.lua @@ -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 @@ function source(dest, candidates) end function destination(candidates, sources) - local t_sort = table.sort; local sourceAddrs = {}; local function comp(ipA, ipB) local ipAsource = sourceAddrs[ipA]; |