From 782ead0dbf3095d0e843c2036bf40cc8ecd9b4d1 Mon Sep 17 00:00:00 2001 From: Ben Johnson Date: Mon, 19 May 2014 12:08:33 -0600 Subject: Fix freelist allocation direction. This commit fixes the freelist so that it frees from the beginning of the data file instead of the end. It also adds a fast path for pages which can be allocated from the first free pages and it includes read transaction stats. --- freelist_test.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'freelist_test.go') diff --git a/freelist_test.go b/freelist_test.go index 2b321a4..00c71cf 100644 --- a/freelist_test.go +++ b/freelist_test.go @@ -36,15 +36,14 @@ func TestFreelist_release(t *testing.T) { // Ensure that a freelist can find contiguous blocks of pages. func TestFreelist_allocate(t *testing.T) { - f := &freelist{ids: []pgid{18, 13, 12, 9, 7, 6, 5, 4, 3}} - assert.Equal(t, f.allocate(2), pgid(12)) - assert.Equal(t, f.allocate(1), pgid(18)) - assert.Equal(t, f.allocate(3), pgid(5)) - assert.Equal(t, f.allocate(3), pgid(0)) - assert.Equal(t, f.allocate(2), pgid(3)) - assert.Equal(t, f.allocate(1), pgid(9)) - assert.Equal(t, f.allocate(0), pgid(0)) - assert.Equal(t, f.ids, []pgid{}) + f := &freelist{ids: []pgid{3, 4, 5, 6, 7, 9, 12, 13, 18}} + assert.Equal(t, 3, int(f.allocate(3))) + assert.Equal(t, 6, int(f.allocate(1))) + assert.Equal(t, 0, int(f.allocate(3))) + assert.Equal(t, 12, int(f.allocate(2))) + assert.Equal(t, 7, int(f.allocate(1))) + assert.Equal(t, 0, int(f.allocate(0))) + assert.Equal(t, []pgid{9, 18}, f.ids) } // Ensure that a freelist can deserialize from a freelist page. -- cgit v1.2.3