mirror of
https://github.com/1bardesign/batteries.git
synced 2024-11-29 16:24:35 +00:00
[added] set:size and set:get(index)
This commit is contained in:
parent
5f124be2f0
commit
699affd1ad
12
set.lua
12
set.lua
@ -46,6 +46,18 @@ function set:remove(v)
|
|||||||
return self
|
return self
|
||||||
end
|
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
|
--iterate the values in the set, along with their index
|
||||||
--the index is useless but harmless, and adding a custom iterator seems
|
--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
|
--like a really easy way to encourage people to use slower-than-optimal code
|
||||||
|
Loading…
Reference in New Issue
Block a user