From 352c32ee129309cf244e64c538d3a287b56ff2fc Mon Sep 17 00:00:00 2001 From: James Mills <1290234+prologic@users.noreply.github.com> Date: Thu, 21 Mar 2019 10:47:50 +1000 Subject: [PATCH] Add Len() to exported API (extended API) --- bitcask.go | 4 ++++ bitcask_test.go | 4 ++++ internal/keydir.go | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/bitcask.go b/bitcask.go index 8f28878..02a6ef5 100644 --- a/bitcask.go +++ b/bitcask.go @@ -125,6 +125,10 @@ func (b *Bitcask) Scan(prefix string, f func(key string) error) error { return nil } +func (b *Bitcask) Len() int { + return b.keydir.Len() +} + func (b *Bitcask) Keys() chan string { return b.keydir.Keys() } diff --git a/bitcask_test.go b/bitcask_test.go index c343f06..d1d542c 100644 --- a/bitcask_test.go +++ b/bitcask_test.go @@ -40,6 +40,10 @@ func TestAll(t *testing.T) { assert.Equal([]byte("bar"), val) }) + t.Run("Len", func(t *testing.T) { + assert.Equal(1, db.Len()) + }) + t.Run("Has", func(t *testing.T) { assert.True(db.Has("foo")) }) diff --git a/internal/keydir.go b/internal/keydir.go index 285d16b..1f60c4c 100644 --- a/internal/keydir.go +++ b/internal/keydir.go @@ -52,6 +52,10 @@ func (k *Keydir) Delete(key string) { delete(k.kv, key) } +func (k *Keydir) Len() int { + return len(k.kv) +} + func (k *Keydir) Keys() chan string { ch := make(chan string) go func() {