From 699affd1ad3de6cfe462b6a69dad3c4e06080bcb Mon Sep 17 00:00:00 2001 From: Max Cahill <1bardesign@gmail.com> Date: Sat, 29 Aug 2020 21:12:56 +1000 Subject: [PATCH] [added] set:size and set:get(index) --- set.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/set.lua b/set.lua index 4cd306f..bf98a8b 100644 --- a/set.lua +++ b/set.lua @@ -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