@cryptotaxi247 / kubo / commits / 96e45c745

Use uint64 for indirect pin refcounts

Platform-dependent behavior is not nice, and negative refcounts are not very useful. License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Tommi Virtanen committed May 8, 2015 at 17:17 UTC 96e45c74572425a1a5a0149a306dc79855ab69f9
3 files changed +9 -9
core/commands/pin.go
+1 -1
@@ -275,7 +275,7 @@ Example:
275
276 type RefKeyObject struct {
277 Type string
278 - Count int
278 + Count uint64
279 }
280
281 type RefKeyList struct {
pin/indirect.go
+6 -6
@@ -6,23 +6,23 @@ import (
6 )
7
8 type indirectPin struct {
9 - refCounts map[key.Key]int
9 + refCounts map[key.Key]uint64
10 }
11
12 func newIndirectPin() *indirectPin {
13 return &indirectPin{
14 - refCounts: make(map[key.Key]int),
14 + refCounts: make(map[key.Key]uint64),
15 }
16 }
17
18 func loadIndirPin(d ds.Datastore, k ds.Key) (*indirectPin, error) {
19 - var rcStore map[string]int
19 + var rcStore map[string]uint64
20 err := loadSet(d, k, &rcStore)
21 if err != nil {
22 return nil, err
23 }
24
25 - refcnt := make(map[key.Key]int)
25 + refcnt := make(map[key.Key]uint64)
26 var keys []key.Key
27 for encK, v := range rcStore {
28 if v > 0 {
@@ -38,7 +38,7 @@ func loadIndirPin(d ds.Datastore, k ds.Key) (*indirectPin, error) {
38
39 func storeIndirPin(d ds.Datastore, k ds.Key, p *indirectPin) error {
40
41 - rcStore := map[string]int{}
41 + rcStore := map[string]uint64{}
42 for k, v := range p.refCounts {
43 rcStore[key.B58KeyEncode(k)] = v
44 }
@@ -65,6 +65,6 @@ func (i *indirectPin) HasKey(k key.Key) bool {
65 return found
66 }
67
68 -func (i *indirectPin) GetRefs() map[key.Key]int {
68 +func (i *indirectPin) GetRefs() map[key.Key]uint64 {
69 return i.refCounts
70 }
pin/pin.go
+2 -2
@@ -46,7 +46,7 @@ type Pinner interface {
46
47 Flush() error
48 DirectKeys() []key.Key
49 - IndirectKeys() map[key.Key]int
49 + IndirectKeys() map[key.Key]uint64
50 RecursiveKeys() []key.Key
51 }
52
@@ -254,7 +254,7 @@ func (p *pinner) DirectKeys() []key.Key {
254 }
255
256 // IndirectKeys returns a slice containing the indirectly pinned keys
257 -func (p *pinner) IndirectKeys() map[key.Key]int {
257 +func (p *pinner) IndirectKeys() map[key.Key]uint64 {
258 return p.indirPin.GetRefs()
259 }
260