Add indirection for large version vectors. (#6376)
This adds indirection of large version vectors in the same manner as we already to block lists. The effect is the same: less duplicated data in some situations. To mitigate the impact for when this indirection wouldn't be needed I've added an indirection cutoff for both blocks and the new version vector stuff: we don't do the indirection at all for small block lists or small version vectors, instead storing it directly like we used to do. This is faster for small files and small setups.
This commit is contained in:
@@ -360,3 +360,16 @@ func BlocksHash(bs []BlockInfo) []byte {
|
||||
}
|
||||
return h.Sum(nil)
|
||||
}
|
||||
|
||||
func VectorHash(v Vector) []byte {
|
||||
h := sha256.New()
|
||||
for _, c := range v.Counters {
|
||||
if err := binary.Write(h, binary.BigEndian, c.ID); err != nil {
|
||||
panic("impossible: failed to write c.ID to hash function: " + err.Error())
|
||||
}
|
||||
if err := binary.Write(h, binary.BigEndian, c.Value); err != nil {
|
||||
panic("impossible: failed to write c.Value to hash function: " + err.Error())
|
||||
}
|
||||
}
|
||||
return h.Sum(nil)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user