1
0
mirror of https://github.com/facebook/zstd.git synced 2025-09-02 15:41:31 +03:00

fixed strict C90 semantic

This commit is contained in:
Yann Collet
2024-09-03 16:44:30 -07:00
parent 52ed013b3f
commit f714778f8e

View File

@@ -36,8 +36,8 @@ typedef struct {
int events[HASHTABLESIZE]; int events[HASHTABLESIZE];
S64 nbEvents; S64 nbEvents;
} FingerPrint; } FingerPrint;
static FingerPrint pastEvents = {}; static FingerPrint pastEvents;
static FingerPrint newEvents = {}; static FingerPrint newEvents;
static void initStats(void) { static void initStats(void) {
memset(&pastEvents, 0, sizeof(pastEvents)); memset(&pastEvents, 0, sizeof(pastEvents));
@@ -48,8 +48,9 @@ static void initStats(void) {
static void addToFingerprint(FingerPrint* fp, const void* src, size_t s) { static void addToFingerprint(FingerPrint* fp, const void* src, size_t s) {
const char* p = src; const char* p = src;
size_t limit = s - HASHLENGTH + 1; size_t limit = s - HASHLENGTH + 1;
size_t n;
assert(s >= HASHLENGTH); assert(s >= HASHLENGTH);
for (size_t n = 0; n < limit; n++) { for (n = 0; n < limit; n++) {
fp->events[hash2(p++)]++; fp->events[hash2(p++)]++;
} }
fp->nbEvents += limit; fp->nbEvents += limit;
@@ -64,7 +65,8 @@ static S64 abs64(S64 i) { return (i < 0) ? -i : i; }
static S64 fpDistance(const FingerPrint *fp1, const FingerPrint *fp2) { static S64 fpDistance(const FingerPrint *fp1, const FingerPrint *fp2) {
S64 distance = 0; S64 distance = 0;
for (size_t n = 0; n < HASHTABLESIZE; n++) { size_t n;
for (n = 0; n < HASHTABLESIZE; n++) {
distance += distance +=
abs64(fp1->events[n] * fp2->nbEvents - fp2->events[n] * fp1->nbEvents); abs64(fp1->events[n] * fp2->nbEvents - fp2->events[n] * fp1->nbEvents);
} }
@@ -73,7 +75,6 @@ static S64 fpDistance(const FingerPrint *fp1, const FingerPrint *fp2) {
// Compare newEvents with pastEvents // Compare newEvents with pastEvents
// return 1 when considered "too different" // return 1 when considered "too different"
// debug:write Deviation value in %
static int compareFingerprints(const FingerPrint* ref, static int compareFingerprints(const FingerPrint* ref,
const FingerPrint* new, const FingerPrint* new,
int penalty) int penalty)
@@ -82,29 +83,34 @@ static int compareFingerprints(const FingerPrint *ref,
return 0; return 0;
{ S64 p50 = ref->nbEvents * new->nbEvents; { S64 p50 = ref->nbEvents * new->nbEvents;
S64 deviation = fpDistance(ref, new); S64 deviation = fpDistance(ref, new);
// printf("Deviation: %.2f%% \n", (double)deviation / (double)ref * 100.);
S64 threshold = p50 * (THRESHOLD_BASE + penalty) / THRESHOLD_PENALTY_RATE; S64 threshold = p50 * (THRESHOLD_BASE + penalty) / THRESHOLD_PENALTY_RATE;
return deviation >= threshold; return deviation >= threshold;
} }
} }
static void mergeEvents(FingerPrint *acc, const FingerPrint *new) { static void mergeEvents(FingerPrint* acc, const FingerPrint* new)
for (size_t n = 0; n < HASHTABLESIZE; n++) { {
size_t n;
for (n = 0; n < HASHTABLESIZE; n++) {
acc->events[n] += new->events[n]; acc->events[n] += new->events[n];
} }
acc->nbEvents += new->nbEvents; acc->nbEvents += new->nbEvents;
} }
static void flushEvents(void) { static void flushEvents(void)
for (size_t n = 0; n < HASHTABLESIZE; n++) { {
size_t n;
for (n = 0; n < HASHTABLESIZE; n++) {
pastEvents.events[n] = newEvents.events[n]; pastEvents.events[n] = newEvents.events[n];
} }
pastEvents.nbEvents = newEvents.nbEvents; pastEvents.nbEvents = newEvents.nbEvents;
memset(&newEvents, 0, sizeof(newEvents)); memset(&newEvents, 0, sizeof(newEvents));
} }
static void removeEvents(FingerPrint *acc, const FingerPrint *slice) { static void removeEvents(FingerPrint* acc, const FingerPrint* slice)
for (size_t n = 0; n < HASHTABLESIZE; n++) { {
size_t n;
for (n = 0; n < HASHTABLESIZE; n++) {
assert(acc->events[n] >= slice->events[n]); assert(acc->events[n] >= slice->events[n]);
acc->events[n] -= slice->events[n]; acc->events[n] -= slice->events[n];
} }