Welcome to mirror list, hosted at ThFree Co, Russian Federation.

probing_hash_utils.cpp « ProbingPT « TranslationModel « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f23f57d6645fe28f96d0a8597c52761d7a4e0220 (plain)
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
49
50
#include "probing_hash_utils.hh"

namespace Moses
{

//Read table from disk, return memory map location
char * readTable(const char * filename, size_t size)
{
  //Initial position of the file is the end of the file, thus we know the size
  int fd;
  char * map;

  fd = open(filename, O_RDONLY);
  if (fd == -1) {
    perror("Error opening file for reading");
    exit(EXIT_FAILURE);
  }

  map = (char *) mmap(0, size, PROT_READ, MAP_SHARED, fd, 0);

  if (map == MAP_FAILED) {
    close(fd);
    perror("Error mmapping the file");
    exit(EXIT_FAILURE);
  }

  return map;
}

void serialize_table(char *mem, size_t size, const std::string &filename)
{
  std::ofstream os(filename.c_str(), std::ios::binary);
  os.write((const char*) &mem[0], size);
  os.close();

}

uint64_t getKey(const uint64_t source_phrase[], size_t size)
{
  //TOO SLOW
  //uint64_t key = util::MurmurHashNative(&source_phrase[0], source_phrase.size());
  uint64_t key = 0;
  for (size_t i = 0; i < size; i++) {
    key += (source_phrase[i] << i);
  }
  return key;
}

}