mirror of
https://github.com/borgbackup/borg.git
synced 2025-03-15 08:29:36 +00:00
Port hashindex_summarize into ChunkIndex.summarize
This commit is contained in:
parent
0a253edcfd
commit
c90745cdbb
3 changed files with 31 additions and 34 deletions
|
@ -440,32 +440,6 @@ hashindex_get_size(HashIndex *index)
|
||||||
return index->num_entries;
|
return index->num_entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
hashindex_summarize(HashIndex *index, long long *total_size, long long *total_csize,
|
|
||||||
long long *total_unique_size, long long *total_unique_csize,
|
|
||||||
long long *total_unique_chunks, long long *total_chunks)
|
|
||||||
{
|
|
||||||
int64_t size = 0, csize = 0, unique_size = 0, unique_csize = 0, chunks = 0, unique_chunks = 0;
|
|
||||||
const int32_t *values;
|
|
||||||
void *key = NULL;
|
|
||||||
|
|
||||||
while((key = hashindex_next_key(index, key))) {
|
|
||||||
values = key + index->key_size;
|
|
||||||
unique_chunks++;
|
|
||||||
chunks += _le32toh(values[0]);
|
|
||||||
unique_size += _le32toh(values[1]);
|
|
||||||
unique_csize += _le32toh(values[2]);
|
|
||||||
size += (int64_t) _le32toh(values[0]) * _le32toh(values[1]);
|
|
||||||
csize += (int64_t) _le32toh(values[0]) * _le32toh(values[2]);
|
|
||||||
}
|
|
||||||
*total_size = size;
|
|
||||||
*total_csize = csize;
|
|
||||||
*total_unique_size = unique_size;
|
|
||||||
*total_unique_csize = unique_csize;
|
|
||||||
*total_unique_chunks = unique_chunks;
|
|
||||||
*total_chunks = chunks;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
hashindex_add(HashIndex *index, const void *key, int32_t *other_values)
|
hashindex_add(HashIndex *index, const void *key, int32_t *other_values)
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,9 +11,6 @@ cdef extern from "_hashindex.c":
|
||||||
HashIndex *hashindex_read(char *path)
|
HashIndex *hashindex_read(char *path)
|
||||||
HashIndex *hashindex_init(int capacity, int key_size, int value_size)
|
HashIndex *hashindex_init(int capacity, int key_size, int value_size)
|
||||||
void hashindex_free(HashIndex *index)
|
void hashindex_free(HashIndex *index)
|
||||||
void hashindex_summarize(HashIndex *index, long long *total_size, long long *total_csize,
|
|
||||||
long long *unique_size, long long *unique_csize,
|
|
||||||
long long *total_unique_chunks, long long *total_chunks)
|
|
||||||
void hashindex_merge(HashIndex *index, HashIndex *other)
|
void hashindex_merge(HashIndex *index, HashIndex *other)
|
||||||
void hashindex_add(HashIndex *index, void *key, void *value)
|
void hashindex_add(HashIndex *index, void *key, void *value)
|
||||||
int hashindex_get_size(HashIndex *index)
|
int hashindex_get_size(HashIndex *index)
|
||||||
|
@ -191,11 +188,23 @@ cdef class ChunkIndex(IndexBase):
|
||||||
return iter
|
return iter
|
||||||
|
|
||||||
def summarize(self):
|
def summarize(self):
|
||||||
cdef long long total_size, total_csize, unique_size, unique_csize, total_unique_chunks, total_chunks
|
cdef long long size = 0, csize = 0, unique_size = 0, unique_csize = 0, chunks = 0, unique_chunks = 0
|
||||||
hashindex_summarize(self.index, &total_size, &total_csize,
|
cdef int *values
|
||||||
&unique_size, &unique_csize,
|
cdef void *key = NULL
|
||||||
&total_unique_chunks, &total_chunks)
|
|
||||||
return total_size, total_csize, unique_size, unique_csize, total_unique_chunks, total_chunks
|
while True:
|
||||||
|
key = hashindex_next_key(self.index, key)
|
||||||
|
if not key:
|
||||||
|
break
|
||||||
|
unique_chunks += 1
|
||||||
|
values = <int*> (key + self.key_size)
|
||||||
|
chunks += _le32toh(values[0])
|
||||||
|
unique_size += _le32toh(values[1])
|
||||||
|
unique_csize += _le32toh(values[2])
|
||||||
|
size += <long long> _le32toh(values[1]) * _le32toh(values[0])
|
||||||
|
csize += <long long> _le32toh(values[2]) * _le32toh(values[0])
|
||||||
|
|
||||||
|
return size, csize, unique_size, unique_csize, unique_chunks, chunks
|
||||||
|
|
||||||
def add(self, key, refs, size, csize):
|
def add(self, key, refs, size, csize):
|
||||||
assert len(key) == self.key_size
|
assert len(key) == self.key_size
|
||||||
|
|
|
@ -100,3 +100,17 @@ class HashIndexTestCase(BaseTestCase):
|
||||||
assert idx1[H(2)] == (7, 200, 200)
|
assert idx1[H(2)] == (7, 200, 200)
|
||||||
assert idx1[H(3)] == (3, 300, 300)
|
assert idx1[H(3)] == (3, 300, 300)
|
||||||
assert idx1[H(4)] == (6, 400, 400)
|
assert idx1[H(4)] == (6, 400, 400)
|
||||||
|
|
||||||
|
def test_chunkindex_summarize(self):
|
||||||
|
idx = ChunkIndex()
|
||||||
|
idx[H(1)] = 1, 1000, 100
|
||||||
|
idx[H(2)] = 2, 2000, 200
|
||||||
|
idx[H(3)] = 3, 3000, 300
|
||||||
|
|
||||||
|
size, csize, unique_size, unique_csize, unique_chunks, chunks = idx.summarize()
|
||||||
|
assert size == 1000 + 2 * 2000 + 3 * 3000
|
||||||
|
assert csize == 100 + 2 * 200 + 3 * 300
|
||||||
|
assert unique_size == 1000 + 2000 + 3000
|
||||||
|
assert unique_csize == 100 + 200 + 300
|
||||||
|
assert chunks == 1 + 2 + 3
|
||||||
|
assert unique_chunks == 3
|
||||||
|
|
Loading…
Add table
Reference in a new issue