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

probing_hash_utils.cpp « probingpt - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e64da72c44ac75438578719169fbd8c8a445e0f3 (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
#include <iostream>
#include "probing_hash_utils.h"
#include "util/file.hh"

namespace probingpt
{

//Read table from disk, return memory map location
char * readTable(const char * filename, util::LoadMethod load_method, util::scoped_fd &file, util::scoped_memory &memory)
{
  //std::cerr << "filename=" << filename << std::endl;
  file.reset(util::OpenReadOrThrow(filename));
  uint64_t total_size_ = util::SizeFile(file.get());

  MapRead(load_method, file.get(), 0, total_size_, memory);

  return (char*) memory.get();
}

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;
}

}