OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 package memory | |
6 | |
7 import ( | |
8 "github.com/luci/gkvlite" | |
9 ) | |
10 | |
11 // boomStore is a gkvlite.Store which will panic for anything which might | |
12 // otherwise return an error. | |
13 // | |
14 // This is reasonable for in-memory Store objects, since the only errors that | |
15 // should occur happen with file IO on the underlying file (which of course | |
16 // doesn't exist. | |
Vadim Sh.
2015/05/24 19:43:26
typo: forgot ")" :)
iannucci
2015/05/24 20:33:54
done
| |
17 type boomStore gkvlite.Store | |
18 | |
19 func newBoomStore() *boomStore { | |
20 ret, err := gkvlite.NewStore(nil) | |
21 if err != nil { | |
22 panic(err) | |
23 } | |
24 return (*boomStore)(ret) | |
25 } | |
26 | |
27 func (bs *boomStore) Snapshot() *boomStore { | |
28 return (*boomStore)((*gkvlite.Store)(bs).Snapshot()) | |
29 } | |
30 | |
31 func (bs *boomStore) MakePrivateCollection(cmp gkvlite.KeyCompare) *boomCollecti on { | |
32 return (*boomCollection)((*gkvlite.Store)(bs).MakePrivateCollection(cmp) ) | |
33 } | |
34 | |
35 func (bs *boomStore) GetCollection(name string) *boomCollection { | |
36 return (*boomCollection)((*gkvlite.Store)(bs).GetCollection(name)) | |
37 } | |
38 | |
39 func (bs *boomStore) SetCollection(name string, cmp gkvlite.KeyCompare) *boomCol lection { | |
40 return (*boomCollection)((*gkvlite.Store)(bs).SetCollection(name, cmp)) | |
41 } | |
42 | |
43 // boomCollection is a gkvlite.Collection which will panic for anything which | |
44 // might otherwise return an error. | |
45 // | |
46 // This is reasonable for in-memory Store objects, since the only errors that | |
47 // should occur happen with file IO on the underlying file (which of course | |
48 // doesn't exist. | |
49 type boomCollection gkvlite.Collection | |
50 | |
51 func (bc *boomCollection) Get(k []byte) []byte { | |
52 ret, err := (*gkvlite.Collection)(bc).Get(k) | |
53 if err != nil { | |
54 panic(err) | |
55 } | |
56 return ret | |
57 } | |
58 | |
59 func (bc *boomCollection) Set(k, v []byte) { | |
60 err := (*gkvlite.Collection)(bc).Set(k, v) | |
61 if err != nil { | |
62 panic(err) | |
63 } | |
64 } | |
65 | |
66 func (bc *boomCollection) Delete(k []byte) bool { | |
67 ret, err := (*gkvlite.Collection)(bc).Delete(k) | |
68 if err != nil { | |
69 panic(err) | |
70 } | |
71 return ret | |
72 } | |
73 | |
74 func (bc *boomCollection) VisitItemsAscend(target []byte, withValue bool, visito r gkvlite.ItemVisitor) { | |
75 err := (*gkvlite.Collection)(bc).VisitItemsAscend(target, withValue, vis itor) | |
76 if err != nil { | |
77 panic(err) | |
78 } | |
79 } | |
80 | |
81 func (bc *boomCollection) VisitItemsDescend(target []byte, withValue bool, visit or gkvlite.ItemVisitor) { | |
82 err := (*gkvlite.Collection)(bc).VisitItemsDescend(target, withValue, vi sitor) | |
83 if err != nil { | |
84 panic(err) | |
85 } | |
86 } | |
87 | |
88 func (bc *boomCollection) GetTotals() (numItems, numBytes uint64) { | |
89 numItems, numBytes, err := (*gkvlite.Collection)(bc).GetTotals() | |
90 if err != nil { | |
91 panic(err) | |
92 } | |
93 return | |
94 } | |
OLD | NEW |