mirror of
https://github.com/aaru-dps/libaaruformat.git
synced 2025-12-16 19:24:40 +00:00
Add hash map implementation for sector deduplication
This commit is contained in:
14
src/write.c
14
src/write.c
@@ -25,6 +25,7 @@
|
||||
#include "aaruformat.h"
|
||||
#include "internal.h"
|
||||
#include "log.h"
|
||||
#include "xxhash.h"
|
||||
|
||||
/**
|
||||
* @brief Writes a sector to the AaruFormat image.
|
||||
@@ -155,6 +156,19 @@ int32_t aaruf_write_sector(void *context, uint64_t sector_address, const uint8_t
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t ddt_entry = 0;
|
||||
|
||||
if(ctx->deduplicate)
|
||||
{
|
||||
// Calculate 64-bit XXH3 hash of the sector
|
||||
TRACE("Hashing sector data for deduplication");
|
||||
uint64_t hash = XXH3_64bits(data, length);
|
||||
|
||||
// Check if the hash is already in the map
|
||||
bool existing = lookup_map(ctx->sectorHashMap, hash, &ddt_entry);
|
||||
TRACE("Block does %s exist in deduplication map", existing ? "already" : "not yet");
|
||||
}
|
||||
|
||||
bool ddt_ok = set_ddt_entry_v2(ctx, sector_address, ctx->currentBlockOffset, ctx->nextBlockPosition, sector_status);
|
||||
|
||||
if(!ddt_ok)
|
||||
|
||||
Reference in New Issue
Block a user