mirror of
https://github.com/borgbackup/borg.git
synced 2025-01-03 05:35:58 +00:00
hashindex: simplify .get
This commit is contained in:
parent
d2fe067647
commit
bdf2602e7c
1 changed files with 5 additions and 14 deletions
|
@ -46,17 +46,14 @@ class ChunkIndex:
|
||||||
def iteritems(self):
|
def iteritems(self):
|
||||||
yield from self.ht.iteritems()
|
yield from self.ht.iteritems()
|
||||||
|
|
||||||
|
def get(self, key, default=None):
|
||||||
|
return self.ht.get(key, default)
|
||||||
|
|
||||||
def add(self, key, refs, size):
|
def add(self, key, refs, size):
|
||||||
v = self.get(key, ChunkIndexEntry(0, 0))
|
v = self.get(key, ChunkIndexEntry(0, 0))
|
||||||
refcount = min(self.MAX_VALUE, v.refcount + refs)
|
refcount = min(self.MAX_VALUE, v.refcount + refs)
|
||||||
self[key] = v._replace(refcount=refcount, size=size)
|
self[key] = v._replace(refcount=refcount, size=size)
|
||||||
|
|
||||||
def get(self, key, default=None):
|
|
||||||
try:
|
|
||||||
return self[key]
|
|
||||||
except KeyError:
|
|
||||||
return default
|
|
||||||
|
|
||||||
def compact(self):
|
def compact(self):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
@ -100,10 +97,7 @@ class FuseVersionsIndex:
|
||||||
return len(self.ht)
|
return len(self.ht)
|
||||||
|
|
||||||
def get(self, key, default=None):
|
def get(self, key, default=None):
|
||||||
try:
|
return self.ht.get(key, default)
|
||||||
return self[key]
|
|
||||||
except KeyError:
|
|
||||||
return default
|
|
||||||
|
|
||||||
|
|
||||||
NSIndex1Entry = namedtuple('NSIndex1Entry', 'segment offset')
|
NSIndex1Entry = namedtuple('NSIndex1Entry', 'segment offset')
|
||||||
|
@ -143,10 +137,7 @@ class NSIndex1:
|
||||||
return len(self.ht)
|
return len(self.ht)
|
||||||
|
|
||||||
def get(self, key, default=None):
|
def get(self, key, default=None):
|
||||||
try:
|
return self.ht.get(key, default)
|
||||||
return self[key]
|
|
||||||
except KeyError:
|
|
||||||
return default
|
|
||||||
|
|
||||||
def pop(self, key, default=_NoDefault):
|
def pop(self, key, default=_NoDefault):
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue