feat: shuffle now prevents repeating same files often

Specifically, shuffle now guarantees no path/url repetition until at least 80% of the playlist/directory has been exhausted.

closes #569
This commit is contained in:
tomasklaen
2023-05-30 20:21:03 +02:00
parent 7e1d26c7a3
commit 442fe6b2e5
4 changed files with 51 additions and 15 deletions

View File

@@ -75,6 +75,13 @@ function itable_index_of(itable, value)
end
end
---@param itable table
---@param value any
---@return boolean
function itable_has(itable, value)
return itable_index_of(itable, value) ~= nil
end
---@param itable table
---@param compare fun(value: any, index: number)
---@param from? number Where to start search, defaults to `1`.
@@ -102,8 +109,21 @@ end
---@param itable table
---@param value any
function itable_remove(itable, value)
return itable_filter(itable, function(item) return item ~= value end)
function itable_delete_value(itable, value)
for index = 1, #itable, 1 do
if itable[index] == value then table.remove(itable, index) end
end
return itable
end
---@param itable table
---@param transformer fun(value: any, index: number) : any
function itable_map(itable, transformer)
local result = {}
for index, value in ipairs(itable) do
result[index] = transformer(value, index)
end
return result
end
---@param itable table