From 5c46dc41deed4fa79aeab23999b388fddf35f8a0 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 16 Aug 2015 16:07:51 +0200 Subject: [PATCH] Add methods to IDSet --- backend/idset.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/backend/idset.go b/backend/idset.go index 25543d8dd..4f27f3489 100644 --- a/backend/idset.go +++ b/backend/idset.go @@ -28,3 +28,22 @@ func (s IDSet) Insert(id ID) { func (s IDSet) Delete(id ID) { delete(s, id) } + +// List returns a slice of all IDs in the set. +func (s IDSet) List() IDs { + list := make(IDs, 0, len(s)) + for id := range s { + list = append(list, id) + } + + return list +} + +func (s IDSet) String() string { + str := s.List().String() + if len(str) < 2 { + return "{}" + } + + return "{" + str[1:len(str)-2] + "}" +}