コード例 #1
0
void fillParentBlock(CryptoNote::ParentBlock& pb) {
  pb.majorVersion = 1;
  pb.minorVersion = 1;

  fillHash(pb.prevId, 120);

  pb.numberOfTransactions = 3;
  size_t branchSize = crypto::tree_depth(pb.numberOfTransactions);
  for (size_t i = 0; i < branchSize; ++i) {
    crypto::hash hash;
    fillHash(hash, static_cast<char>(i));
    pb.minerTxBranch.push_back(hash);
  }

  fillTransaction(pb.minerTx);

  CryptoNote::tx_extra_merge_mining_tag mmTag;
  mmTag.depth = 10;
  fillHash(mmTag.merkle_root);
  pb.minerTx.extra.clear();
  CryptoNote::append_mm_tag_to_extra(pb.minerTx.extra, mmTag);

  std::string my;
  std::copy(pb.minerTx.extra.begin(), pb.minerTx.extra.end(), std::back_inserter(my));

  for (size_t i = 0; i < mmTag.depth; ++i) {
    crypto::hash hash;
    fillHash(hash, static_cast<char>(i));
    pb.blockchainBranch.push_back(hash);
  }
}
void fillBlockHeader(cryptonote::BlockHeader& header) {
  header.majorVersion = 1;
  header.minorVersion = 1;
  header.nonce = 0x807F00AB;
  header.timestamp = 1408106672;
  fillHash(header.prevId);
}
コード例 #3
0
TEST(BinarySerializationCompatibility, tx_extra_merge_mining_tag) {
  CryptoNote::tx_extra_merge_mining_tag tag;
  tag.depth = 0xdeadbeef;
  fillHash(tag.merkle_root);

  checkCompatibility(tag);
}
TEST(BinarySerializationCompatibility, Block) {
  cryptonote::Block block;
  fillBlockHeader(block);
  fillTransaction(block.minerTx);

  for (size_t i = 0; i < 7; ++i) {
    crypto::hash hash;
    fillHash(hash, 0x7F + i);
    block.txHashes.push_back(hash);
  }

  checkCompatibility(block);
}
コード例 #5
0
TEST(BinarySerializationCompatibility, BlockVersion2) {
  CryptoNote::Block block;
  fillBlockHeaderVersion2(block);
  fillParentBlock(block.parentBlock);
  fillTransaction(block.minerTx);

  for (size_t i = 0; i < 7; ++i) {
    crypto::hash hash;
    fillHash(hash, static_cast<char>(0x7F + i));
    block.txHashes.push_back(hash);
  }

  checkCompatibility(block);
}
コード例 #6
0
ファイル: distance.cpp プロジェクト: cservan/tercpp
  distance::distance(string filename)
  {
    strcpy(file_name, filename.c_str());
    f = fopen(file_name, "rb");
    if (f == NULL) 
    {
      printf("Word2Vec Model file not found\n");
      exit(-1);
    }
    fscanf(f, "%lld", &words);
    fscanf(f, "%lld", &size);
    vocab = (char *)malloc((long long)words * max_w * sizeof(char));
    for (a = 0; a < N; a++) bestw[a] = (char *)malloc(max_size * sizeof(char));
    M = (float *)malloc((long long)words * (long long)size * sizeof(float));
//     D = (float *)malloc((long long)words * (long long)words * sizeof(float));
//     L = (float *)malloc((long long)words * sizeof(float));
    if (M == NULL) 
    {
      printf("Cannot allocate memory: %lld MB    %lld  %lld\n", (long long)words * size * sizeof(float) / 1048576, words, size);
      exit(-1);
    }
    cerr << "Loading word2vec model...";
//     printf("Allocation of memory: %lld MB    %lld  %lld\n", (long long)words * size * sizeof(float) / 1048576, words, size);
    for (b = 0; b < words; b++) 
    {
      a = 0;
      while (1) 
      {
	vocab[b * max_w + a] = fgetc(f);
	if (feof(f) || (vocab[b * max_w + a] == ' ')) break;
	if ((a < max_w) && (vocab[b * max_w + a] != '\n')) a++;
      }
      vocab[b * max_w + a] = 0;
      for (a = 0; a < size; a++) fread(&M[a + b * size], sizeof(float), 1, f);
      len = 0;
      for (a = 0; a < size; a++) len += M[a + b * size] * M[a + b * size];
      len = sqrt(len);
      for (a = 0; a < size; a++) M[a + b * size] /= len;
    }
    fclose(f);
    
//     mvocab = new multimap < string, int >;
//     for (b = 0; b < words; b++) 
//     {
// // 	pair < string, int > p(string(&vocab[b * max_w]),b);
//  	mvocab->insert(make_pair < string, int > (string(&vocab[b * max_w]),b));
//     }
    
//     for (b = 0; b < words; b++) 
//     {
// 	len = 0;
// 	for (a = 0; a < size; a++) len += M[a + b * size] * M[a + b * size];
// 	L[b] = sqrt(len);
//     }
//     for (b = 0; b < words; b++) 
//     {
// 	for (c = 0; c <= b; c++) 
// 	{
// 	    D[b*c] = 0.0;
// 	    for (a = 0; a < size; a++) 
// 	    {
// 		D[b*c] += (M[a + b * size] / L[b]) * (M[a + c * size] / L[c]);
// 	    }
// 	}
//     }

//     cerr << mvocab->size() <<endl;
    fillHash();
    cerr << "finished!" <<endl;
  }