Commit 96e45c74 authored by Tommi Virtanen's avatar Tommi Virtanen Committed by Jeromy

Use uint64 for indirect pin refcounts

Platform-dependent behavior is not nice, and negative refcounts are
not very useful.

License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>
parent fecfb76c
...@@ -275,7 +275,7 @@ Example: ...@@ -275,7 +275,7 @@ Example:
type RefKeyObject struct { type RefKeyObject struct {
Type string Type string
Count int Count uint64
} }
type RefKeyList struct { type RefKeyList struct {
......
...@@ -6,23 +6,23 @@ import ( ...@@ -6,23 +6,23 @@ import (
) )
type indirectPin struct { type indirectPin struct {
refCounts map[key.Key]int refCounts map[key.Key]uint64
} }
func newIndirectPin() *indirectPin { func newIndirectPin() *indirectPin {
return &indirectPin{ return &indirectPin{
refCounts: make(map[key.Key]int), refCounts: make(map[key.Key]uint64),
} }
} }
func loadIndirPin(d ds.Datastore, k ds.Key) (*indirectPin, error) { func loadIndirPin(d ds.Datastore, k ds.Key) (*indirectPin, error) {
var rcStore map[string]int var rcStore map[string]uint64
err := loadSet(d, k, &rcStore) err := loadSet(d, k, &rcStore)
if err != nil { if err != nil {
return nil, err return nil, err
} }
refcnt := make(map[key.Key]int) refcnt := make(map[key.Key]uint64)
var keys []key.Key var keys []key.Key
for encK, v := range rcStore { for encK, v := range rcStore {
if v > 0 { if v > 0 {
...@@ -38,7 +38,7 @@ func loadIndirPin(d ds.Datastore, k ds.Key) (*indirectPin, error) { ...@@ -38,7 +38,7 @@ func loadIndirPin(d ds.Datastore, k ds.Key) (*indirectPin, error) {
func storeIndirPin(d ds.Datastore, k ds.Key, p *indirectPin) error { func storeIndirPin(d ds.Datastore, k ds.Key, p *indirectPin) error {
rcStore := map[string]int{} rcStore := map[string]uint64{}
for k, v := range p.refCounts { for k, v := range p.refCounts {
rcStore[key.B58KeyEncode(k)] = v rcStore[key.B58KeyEncode(k)] = v
} }
...@@ -65,6 +65,6 @@ func (i *indirectPin) HasKey(k key.Key) bool { ...@@ -65,6 +65,6 @@ func (i *indirectPin) HasKey(k key.Key) bool {
return found return found
} }
func (i *indirectPin) GetRefs() map[key.Key]int { func (i *indirectPin) GetRefs() map[key.Key]uint64 {
return i.refCounts return i.refCounts
} }
...@@ -46,7 +46,7 @@ type Pinner interface { ...@@ -46,7 +46,7 @@ type Pinner interface {
Flush() error Flush() error
DirectKeys() []key.Key DirectKeys() []key.Key
IndirectKeys() map[key.Key]int IndirectKeys() map[key.Key]uint64
RecursiveKeys() []key.Key RecursiveKeys() []key.Key
} }
...@@ -254,7 +254,7 @@ func (p *pinner) DirectKeys() []key.Key { ...@@ -254,7 +254,7 @@ func (p *pinner) DirectKeys() []key.Key {
} }
// IndirectKeys returns a slice containing the indirectly pinned keys // IndirectKeys returns a slice containing the indirectly pinned keys
func (p *pinner) IndirectKeys() map[key.Key]int { func (p *pinner) IndirectKeys() map[key.Key]uint64 {
return p.indirPin.GetRefs() return p.indirPin.GetRefs()
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment