From 278e867c8cae8147a1d83566a4a684d5558ba541 Mon Sep 17 00:00:00 2001 From: Florian Zeitz Date: Sun, 6 Nov 2011 18:23:16 +0100 Subject: util.rfc3484: Use a stable sorting algorithm --- util/rfc3484.lua | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'util') 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]; -- cgit v1.2.3