[added] set:size and set:get(index)

This commit is contained in:
Max Cahill 2020-08-29 21:12:56 +10:00
parent 5f124be2f0
commit 699affd1ad

12
set.lua
View File

@ -46,6 +46,18 @@ function set:remove(v)
return self
end
--get the number of distinct values in the set
function set:size()
return #self._ordered
end
--return a value from the set
--index must be between 1 and size() inclusive
--adding/removing invalidates indices
function set:get(index)
return self._ordered[index]
end
--iterate the values in the set, along with their index
--the index is useless but harmless, and adding a custom iterator seems
--like a really easy way to encourage people to use slower-than-optimal code