From 3c2715dfdeead1da8c873747776c7500b4806971 Mon Sep 17 00:00:00 2001 From: millken Date: Tue, 5 Apr 2022 20:16:44 +0800 Subject: [PATCH] format code --- entry.go | 1 + index.go | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/entry.go b/entry.go index a0ef1be..32689d4 100644 --- a/entry.go +++ b/entry.go @@ -43,6 +43,7 @@ type entry struct { func (hdr EntryHeader) EntrySize() uint32 { return EntryHeaderSize + uint32(hdr.KeySize) + hdr.ValueSize } + func (e *EntryHeader) Encode() []byte { var b [EntryHeaderSize]byte intconv.PutUint32(b[0:4], e.ValueSize) diff --git a/index.go b/index.go index fcd4f5c..b0a2406 100644 --- a/index.go +++ b/index.go @@ -59,17 +59,17 @@ func (b *bucket) Init() { func (b *bucket) Reset() { b.mu.Lock() + defer b.mu.Unlock() bm := b.items for k := range bm { - delete(bm, k) + delete(b.items, k) } - b.mu.Unlock() } -func (b *bucket) Set(k uint64, item item) error { +func (b *bucket) Set(k uint64, it item) error { b.mu.Lock() - b.items[k] = item - b.mu.Unlock() + defer b.mu.Unlock() + b.items[k] = it return nil }