Пример #1
0
/**
 * @brief Creates a hash table structure for performing LSH.
 *
 * @param table_size Size of the hash table
 * @param tuple_size Number of hash functions per sketch
 * @param dim Dimensions of the vectors to be hashed
 *
 * @return Hash table structure
 */
HashTableLP lplsh_create(uint table_size, uint tuple_size, uint dim, double width)
{
     uint i;
     HashTableLP hash_table;

     hash_table.table_size = table_size;
     hash_table.tuple_size = tuple_size; 
     hash_table.dim = dim;
     hash_table.width = width;
     
     hash_table.avec = (double *) malloc(tuple_size * dim * sizeof(double));
     hash_table.bval = (double *) malloc(tuple_size *  sizeof(double));
     hash_table.buckets = (BucketLP *) calloc(table_size, sizeof(BucketLP));
     list_init(&hash_table.used_buckets);

     // generates array of random values for universal hashing
     hash_table.a = (uint *) malloc(tuple_size * sizeof(uint));
     hash_table.b = (uint *) malloc(tuple_size * sizeof(uint));
     for (i = 0; i < tuple_size; i++){
          hash_table.a[i] = (unsigned int) (genrand64_int64() & 0xFFFFFFFF);
          hash_table.b[i] = (unsigned int) (genrand64_int64() & 0xFFFFFFFF);
     }
     
     return hash_table;
}
Пример #2
0
void init_zobrist_keys(void)
{
    int i, j;

    init_genrand64(mt64_seed);

    for (i = 0; i < 12; ++i)
    {
        for (j = 0; j < 64; ++j)
        {
            pieceKeys[i][j] = genrand64_int64();
        }
    }

    blackToMoveKey = genrand64_int64();

    for (i = 0; i < 16; ++i)
    {
        castlingKeys[i] = genrand64_int64();
    }

    for (i = 0; i < 8; ++i)
    {
        enPassantKeys[i] = genrand64_int64();
    }
}
Пример #3
0
Zobrist::Zobrist()
{
  zob_key = 0;
  zob_side = genrand64_int64();
  for(int i = 0; i < MAXSIZE2; i++){
    zob_points [0][i] = genrand64_int64();
    zob_points [1][i] = genrand64_int64();
    zob_ko[i] = genrand64_int64();
  }
  clear_history();
}
Пример #4
0
uint16_t
mt_rand16(void)
{
    //uint16_t temp = genrand64_int64() & 0xffff;
    return genrand64_int64() & 0xffff;
    
} // mt_rand16()...
Пример #5
0
void l1lsh_generate_sample_bits(uint dim, uint max_value, uint tuple_size, SampleBits *sample_bits,
                                uint *number_of_samples)
{
     uint i;
     uint *usedbits = (uint *) calloc(dim * max_value, sizeof(uint));
     
     for(i = 0; i < tuple_size; i++) {
          sample_bits[i].dim = genrand64_int64() % dim;
          sample_bits[i].loc = genrand64_int64() % max_value;
          uint bitnum = sample_bits[i].dim * max_value + sample_bits[i].loc;
          while(usedbits[bitnum]){
               sample_bits[i].dim = genrand64_int64() % dim;
               sample_bits[i].loc = genrand64_int64() % max_value;
               bitnum = sample_bits[i].dim * max_value + sample_bits[i].loc;
          }
          usedbits[bitnum] = 1;
          number_of_samples[sample_bits[i].dim]++;
	  
     }
     qsort(sample_bits, tuple_size, sizeof(SampleBits), l1lsh_sample_bit_compare);	
} 
Пример #6
0
/**
 * @brief Creates a hash table structure for performing Min-Hash
 *        on a collection of list.
 *
 * @param Number of MinHash values per tuple
 * @param dim Largest item value in the database of lists
 * @param table_size Number of buckets in the hash table
 *
 * @return Hash table structure
 */
HashTable mh_create(uint table_size, uint tuple_size, uint dim)
{
     uint i;
     HashTable hash_table;

     hash_table.table_size = table_size;
     hash_table.tuple_size = tuple_size; 
     hash_table.dim = dim; 
     hash_table.permutations = (RandomValue *) malloc(tuple_size * dim * sizeof(RandomValue)); 
    
     hash_table.buckets = (Bucket *) calloc(table_size, sizeof(Bucket));
     list_init(&hash_table.used_buckets);

     // generates array of random values for universal hashing
     hash_table.a = (uint *) malloc(tuple_size * sizeof(uint));
     hash_table.b = (uint *) malloc(tuple_size * sizeof(uint));
     for (i = 0; i < tuple_size; i++){
          hash_table.a[i] = (unsigned int) (genrand64_int64() & 0xFFFFFFFF);
          hash_table.b[i] = (unsigned int) (genrand64_int64() & 0xFFFFFFFF);
     }
     
     return hash_table;
}
Пример #7
0
/**
 * @brief Assigns, for each MinHash function, a random positive integer 
 *        and a uniformly distributed U(0,1) number to each possible 
 *        item in the database of lists.
 * 
 * @param dim Largest item value in the database of lists
 * @param tuple_size Number of MinHash values per tuple
 * @param permutations Random positive integers assigned to each possible item 
 */
void mh_generate_permutations(uint dim, uint tuple_size, RandomValue *permutations)
{
     uint i, j;
     ullong rnd;

     // generates random permutations by assigning a random value to each item
     // of the universal set
     for (i = 0; i < tuple_size; i++){ 
          for (j = 0; j < dim; j++){
               rnd = genrand64_int64();
               permutations[i * dim + j].random_int = rnd;
               permutations[i * dim + j].random_double = -logl((rnd >> 11) * (1.0/9007199254740991.0));
          }
     }
}
Пример #8
0
/**
 * @brief Creates a hash table structure for performing LSH.
 *
 * @param table_size Size of the hash table
 * @param tuple_size Number of hash functions per sketch
 * @param dim Dimensions of the vectors to be hashed
 *
 * @return Hash table structure
 */
HashTableL1 l1lsh_create(uint table_size, uint tuple_size, uint dim, uint max_value)
{
     uint i;
     HashTableL1 hash_table;

     hash_table.table_size = table_size;
     hash_table.tuple_size = tuple_size; 
     hash_table.dim = dim;
     hash_table.max_value = max_value; 
     hash_table.sample_bits = (SampleBits *) malloc(tuple_size * sizeof(SampleBits)); 
     hash_table.number_of_samples = (uint *) calloc(dim, sizeof(uint));    
     hash_table.buckets = (BucketL1 *) calloc(table_size, sizeof(BucketL1));
     list_init(&hash_table.used_buckets);

     // generates array of random values for universal hashing
     hash_table.a = (uint *) malloc(tuple_size * sizeof(uint));
     hash_table.b = (uint *) malloc(tuple_size * sizeof(uint));
     for (i = 0; i < tuple_size; i++){
          hash_table.a[i] = (unsigned int) (genrand64_int64() & 0xFFFFFFFF);
          hash_table.b[i] = (unsigned int) (genrand64_int64() & 0xFFFFFFFF);
     }
     
     return hash_table;
}
Пример #9
0
	void obme_init()
	{
		// Init random generator
		init_genrand64(time(NULL));
		
		// Allocates the mask in the heap because of security reasons.
		_OBME_MASK = new obme_t();
		*_OBME_MASK = 0;
		
		do {
			*_OBME_MASK = genrand64_int64();
			
		// almost impossible, 5.42 * 10^-20
		} while(*_OBME_MASK == 0);
		
		// printf("%llX\n", *_OBME_MASK);
	}
Пример #10
0
int main (int argc, const char * argv[]) {
    uint count = -1;
    uint seed = get_time();
    char *filename = NULL;

    get_args(argc, (char**)argv, &filename, &count, &seed);

    init_genrand64(seed);

    FILE *fp;
    if (filename) {
        printf("Initial Seed              : %d\n", seed);
        fp = fopen(filename, "wb");
    } else {
        fp = stdout;
    }

    if (fp == NULL) {
        printf("Error creating file");
        return -1;
    }

    uint64_t *val = calloc(BUFFER_SIZE, sizeof(uint64_t));
    uint64_t bytes = 0;
    start_time = get_time();
    uint64_t i = 0;
    uint64_t j = 0;
    for (j = 0; j < count || count == -1; j++){
        for (i = 0; i < BUFFER_SIZE; i++){
            val[i] = genrand64_int64();
        }
        bytes += fwrite(val, sizeof(uint64_t), BUFFER_SIZE, fp);
    }
    end_time = get_time();

    if (filename) {
        printf("Time (seconds)            : %f\n", end_time - start_time);
        printf("Megabytes (10^6) written  : %f\n", bytes * sizeof(uint64_t) / 1000000.0);
        printf("Megabytes / second        : %f\n", (bytes * sizeof(uint64_t) / 1000000.0) / (end_time - start_time));
        fclose(fp);
    }

    return 0;
}
Пример #11
0
 /* generates a random number on (0,1)-real-interval */
 double RandomNumber3(void)
 {
   return ((genrand64_int64()>>12)+0.5)*(1.0/4503599627370496.0);
 }
Пример #12
0
 /* generates a random number on [0,1)-real-interval */
 double RandomNumber2(void)
 {
   return (genrand64_int64()>>11)*(1.0/9007199254740992.0);
 }
Пример #13
0
 /* generates a random number on [0, 2^63-1]-interval */
 long long RandomInteger(void)
 {
   return (long long)(genrand64_int64()>>1);
 }