-
Notifications
You must be signed in to change notification settings - Fork 0
/
projection_family.c
49 lines (37 loc) · 1.04 KB
/
projection_family.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "projection_family.h"
#include <stdlib.h>
projection_family_t*
init_random_projections(unsigned int dim, unsigned int seed,
unsigned int bin_width, size_t projNb)
{
projection_family_t* pfamily = malloc(sizeof(projection_family_t));
normal_generator_t gen = init_normal_distribution(seed);
size_t i;
if (!pfamily)
return NULL;
pfamily->projections = malloc(projNb * sizeof(projection_t*));
pfamily->projection_nb = projNb;
if (!pfamily->projections)
return pfamily;
for (i = 0; i < projNb; i++)
pfamily->projections[i] =
init_random_projection_rng(dim, seed, bin_width, &gen);
return pfamily;
}
void
free_projection_family(projection_family_t* pfamily)
{
size_t i;
for (i = 0; i < pfamily->projection_nb; i++)
free(pfamily->projections[i]);
free(pfamily);
}
int
lsh_data(projection_family_t* pfamily, double* data)
{
size_t i;
int hash = 1;
for (i = 0; i < pfamily->projection_nb; i++)
hash = 33 * hash + project_data(pfamily->projections[i], data);
return hash;
}