From c631b5c7389fa7fa2463f3c865a5b04e9b53c0b9 Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Tue, 17 Feb 2015 22:39:16 +0100 Subject: [PATCH] Add Len() functions for IDSet and Map --- backend/id_set.go | 7 +++++++ map.go | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/backend/id_set.go b/backend/id_set.go index 6b36e0aba..253147605 100644 --- a/backend/id_set.go +++ b/backend/id_set.go @@ -66,3 +66,10 @@ func (s *IDSet) Find(id ID) error { return nil } + +func (s *IDSet) Len() int { + s.m.Lock() + defer s.m.Unlock() + + return len(s.list) +} diff --git a/map.go b/map.go index 1a5b385c4..080e46f25 100644 --- a/map.go +++ b/map.go @@ -140,6 +140,14 @@ func (bl *Map) Equals(other *Map) bool { return true } +// Len returns the number of blobs in the map. +func (bl *Map) Len() int { + bl.m.Lock() + defer bl.m.Unlock() + + return len(bl.list) +} + // Prune deletes all IDs from the map except the ones listed in ids. func (m *Map) Prune(ids *backend.IDSet) { m.m.Lock()