Move normalized_edit_distance function to distance.c
This commit is contained in:
parent
3f074d2bf9
commit
c71e9b2cd7
3 changed files with 15 additions and 11 deletions
|
@ -12,3 +12,15 @@ unsigned int hamming(size_t len, const unsigned char s1[static len],
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double normalized_edit_distance(
|
||||||
|
unsigned int block_size, unsigned int blocks_count,
|
||||||
|
const unsigned char buf[static block_size * blocks_count]) {
|
||||||
|
double avg_dist = 0;
|
||||||
|
for (size_t i = 0; i < blocks_count - 1; ++i) {
|
||||||
|
avg_dist +=
|
||||||
|
hamming(block_size, &buf[i * block_size], &buf[(i + 1) * block_size]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return avg_dist / (double)block_size / ((double)blocks_count - 1.0);
|
||||||
|
}
|
||||||
|
|
|
@ -5,5 +5,8 @@
|
||||||
|
|
||||||
unsigned int hamming(size_t len, const unsigned char s1[static len],
|
unsigned int hamming(size_t len, const unsigned char s1[static len],
|
||||||
const unsigned char s2[static len]);
|
const unsigned char s2[static len]);
|
||||||
|
double normalized_edit_distance(
|
||||||
|
unsigned int block_size, unsigned int blocks_count,
|
||||||
|
const unsigned char buf[static block_size * blocks_count]);
|
||||||
|
|
||||||
#endif /* DISTANCE_H */
|
#endif /* DISTANCE_H */
|
||||||
|
|
|
@ -8,17 +8,6 @@
|
||||||
|
|
||||||
#define BUF_SIZE 4096
|
#define BUF_SIZE 4096
|
||||||
|
|
||||||
double normalized_edit_distance(
|
|
||||||
unsigned int keysize, unsigned int blocks_count,
|
|
||||||
const unsigned char buf[static keysize * blocks_count]) {
|
|
||||||
double avg_dist = 0;
|
|
||||||
for (size_t i = 0; i < blocks_count - 1; ++i) {
|
|
||||||
avg_dist += hamming(keysize, &buf[i * keysize], &buf[(i + 1) * keysize]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return avg_dist / (double)keysize / ((double)blocks_count - 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
if (argc < 2) {
|
if (argc < 2) {
|
||||||
printf("Usage: %s <filename>\n", argv[0]);
|
printf("Usage: %s <filename>\n", argv[0]);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue