<commit_before>/*
 * util.hpp
 *
 *  Created on: Feb 28, 2015
 *      Author: hugo
 */

#ifndef MFLASH_CPP_CORE_UTIL_HPP_
#define MFLASH_CPP_CORE_UTIL_HPP_

#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <unistd.h>

#include "../core/type.hpp"

using namespace std;

namespace mflash {

const int MFLASH_MATRIX_THREADS = 1;
const int MFLASH_VECTOR_THREADS = 1;
const double MAPPING_PERCENTAGE = 0.1;

const string FILE_SEPARATOR = "/";
const string DIRECTORY = ".G-FLASH";
const string GRAPH = "graph";
const string STREAM_FILE = "edge_stream";

const int64 DEFAULT_BYTES_BLOCK = sizeof(int64) * 5; // 40 BYTES

int64 MEMORY_SIZE_BYTES = 1 * 1073741824L; //2GB

int64 get_mapping_limit(int64 block_size_bytes) {
	return 1048576; //MAPPING_PERCENTAGE * block_size_bytes;
}

string get_parent_directory(string graph) {
	int64 pos = graph.find_last_of(FILE_SEPARATOR);

	return graph.substr(0, pos) + FILE_SEPARATOR;
}

string get_mflash_directory(string graph) {
	string path = get_parent_directory(graph) + DIRECTORY;

	/*	boost::filesystem::path dir(path);

	 if( !boost::filesystem::exists(path) ){
	 boost::filesystem::create_directories(path);
	 }*/
	return path;
}

string get_stream_file(string graph) {
	return get_parent_directory(graph) + DIRECTORY + FILE_SEPARATOR
			+ STREAM_FILE;
}

string get_block_file(string graph, int64 i, int64 j) {
	std::stringstream file;
	file << get_mflash_directory(graph) << FILE_SEPARATOR << i << "_" << j
			<< ".block";
	return file.str();
}

bool exist_file(string file) {
	ifstream f(file.c_str());
	if (f.good()) {
		f.close();
		return true;
	} else {
		f.close();
		return false;
	}
}<commit_msg>Method to get partition filename<commit_after>/*
 * util.hpp
 *
 *  Created on: Feb 28, 2015
 *      Author: hugo
 */

#ifndef MFLASH_CPP_CORE_UTIL_HPP_
#define MFLASH_CPP_CORE_UTIL_HPP_

#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
#include <unistd.h>

#include "../core/type.hpp"

using namespace std;

namespace mflash {

const int MFLASH_MATRIX_THREADS = 1;
const int MFLASH_VECTOR_THREADS = 1;
const double MAPPING_PERCENTAGE = 0.1;

const string FILE_SEPARATOR = "/";
const string DIRECTORY = ".G-FLASH";
const string GRAPH = "graph";
const string STREAM_FILE = "edge_stream";

const int64 DEFAULT_BYTES_BLOCK = sizeof(int64) * 5; // 40 BYTES

int64 MEMORY_SIZE_BYTES = 1 * 1073741824L; //2GB

int64 get_mapping_limit(int64 block_size_bytes) {
	return 1048576; //MAPPING_PERCENTAGE * block_size_bytes;
}

string get_parent_directory(string graph) {
	int64 pos = graph.find_last_of(FILE_SEPARATOR);

	return graph.substr(0, pos) + FILE_SEPARATOR;
}

string get_mflash_directory(string graph) {
	string path = get_parent_directory(graph) + DIRECTORY;

	/*	boost::filesystem::path dir(path);

	 if( !boost::filesystem::exists(path) ){
	 boost::filesystem::create_directories(path);
	 }*/
	return path;
}

string get_stream_file(string graph) {
	return get_parent_directory(graph) + DIRECTORY + FILE_SEPARATOR
			+ STREAM_FILE;
}

string get_block_file(string graph, int64 i, int64 j) {
	std::stringstream file;
	file << get_mflash_directory(graph) << FILE_SEPARATOR << i << "_" << j
			<< ".block";
	return file.str();
}

string get_partition_file(string graph, int64 partition_id) {
	std::stringstream file;
	file << get_mflash_directory(graph) << FILE_SEPARATOR << partition_id << ".partition";
	return file.str();
}

bool exist_file(string file) {
	ifstream f(file.c_str());
	if (f.good()) {
		f.close();
		return true;
	} else {
		f.close();
		return false;
	}
}
{'fraction_non_alphanumeric': 0.12782584426458274, 'fraction_numerical': 0.027909572983533353, 'mean_word_length': 5.0033500837520934, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7005602', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1316, 'n_words': 296}