Use array instead of hash for backend.ID

Since backend.ID is always a slice of constant length, use an array
instead of a slice. Mostly, arrays behave as slices, except that an
array cannot be nil, so use `*backend.ID` insteaf of `backend.ID` in
places where the absence of an ID is possible (e.g. for the Subtree of a
Node, which may not present when the node is a file node).

This change allows to directly use backend.ID as the the key for a map,
so that arbitrary data structures (e.g. a Set implemented as a
map[backend.ID]struct{}) can easily be formed.
This commit is contained in:
Alexander Neumann 2015-07-25 17:05:45 +02:00
parent 2fa6124545
commit 5cdcc99eba
31 changed files with 244 additions and 208 deletions

View file

@ -203,25 +203,25 @@ func TestLockRefresh(t *testing.T) {
lock, err := restic.NewLock(repo)
OK(t, err)
var lockID backend.ID
var lockID *backend.ID
for id := range repo.List(backend.Lock, nil) {
if lockID != nil {
t.Error("more than one lock found")
}
lockID = id
lockID = &id
}
OK(t, lock.Refresh())
var lockID2 backend.ID
var lockID2 *backend.ID
for id := range repo.List(backend.Lock, nil) {
if lockID2 != nil {
t.Error("more than one lock found")
}
lockID2 = id
lockID2 = &id
}
Assert(t, !lockID.Equal(lockID2),
Assert(t, !lockID.Equal(*lockID2),
"expected a new ID after lock refresh, got the same")
OK(t, lock.Unlock())
}