fix: replace utils.difference by utils.shallowDiff
This commit is contained in:
parent
e9ebf63c55
commit
930b104522
@ -385,8 +385,8 @@ local function replantProcedure()
|
|||||||
error('cannot fetch the remote plan')
|
error('cannot fetch the remote plan')
|
||||||
end
|
end
|
||||||
|
|
||||||
local seedsToRemove = utils.difference(localPlan, remotePlan)
|
local seedsToRemove = utils.shallowDiff(localPlan, remotePlan)
|
||||||
local seedsToPlant = utils.difference(remotePlan, localPlan)
|
local seedsToPlant = utils.shallowDiff(remotePlan, localPlan)
|
||||||
|
|
||||||
if utils.sizeof(seedsToRemove) > 0 then
|
if utils.sizeof(seedsToRemove) > 0 then
|
||||||
print('nb seeds to remove: ' .. utils.sizeof(seedsToRemove))
|
print('nb seeds to remove: ' .. utils.sizeof(seedsToRemove))
|
||||||
|
|||||||
@ -12,15 +12,31 @@ utils.sizeof = function(t)
|
|||||||
return size
|
return size
|
||||||
end
|
end
|
||||||
|
|
||||||
utils.difference = function(a, b)
|
utils.shallowDiff = function(a, b)
|
||||||
local aa = {}
|
local counters = {}
|
||||||
for k,v in pairs(a) do aa[v]=true end
|
|
||||||
for k,v in pairs(b) do aa[v]=nil end
|
for k,v in pairs(a) do
|
||||||
|
local currentCounter = counters[v] or 0
|
||||||
|
counters[v] = currentCounter + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
for k,v in pairs(b) do
|
||||||
|
if counters[v] then
|
||||||
|
counters[v] = counters[v] - 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local ret = {}
|
local ret = {}
|
||||||
local n = 0
|
local n = 0
|
||||||
|
|
||||||
for k,v in pairs(a) do
|
for k,v in pairs(a) do
|
||||||
if aa[v] then n=n+1 ret[n]=v end
|
if counters[v] and counters[v] > 0 then
|
||||||
|
counters[v] = counters[v] - 1
|
||||||
|
n = n + 1
|
||||||
|
ret[n] = v
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user