# HG changeset patch # User Florian Zeitz # Date 1320600196 -3600 # Node ID ded726418b1658d0ffbbb7c5951b458c2b210364 # Parent c25dee24623f9dcde61d4dac5e4ec66c82f79d5c util.rfc3484: Use a stable sorting algorithm diff -r c25dee24623f -r ded726418b16 util/rfc3484.lua --- 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];