<commit_before>#ifndef MORTON_H_
#define MORTON_H_

#include <stdint.h>
#include <limits.h>

using namespace std;

// encode a given (x,y,z) coordinate to a 64-bit morton code
inline uint64_t mortonEncode_for(unsigned int x, unsigned int y, unsigned int z); // slowest
inline uint64_t mortonEncode_magicbits(unsigned int x, unsigned int y, unsigned int z); // faster
inline uint64_t mortonEncode_LUT(unsigned int x, unsigned int y, unsigned int z); // fastest

// decode a given morton code into X,Y,Z coordinates
inline void mortonDecode_for(uint64_t morton, unsigned int& x, unsigned int& y, unsigned int& z); // slowest
inline unsigned int mortonDecode_magicbits_X(uint64_t morton); // faster
inline unsigned int mortonDecode_magicbits_Y(uint64_t morton);
inline unsigned int mortonDecode_magicbits_Z(uint64_t morton);

// VERSION WITH FOR LOOP
// ---------------------
inline uint64_t mortonEncode_for(unsigned int x, unsigned int y, unsigned int z){
	uint64_t answer = 0;
	for (uint64_t i = 0; i < (sizeof(uint64_t)* CHAR_BIT)/3; ++i) {
		answer |= ((x & ((uint64_t)1 << i)) << 2*i) | ((y & ((uint64_t)1 << i)) << (2*i + 1)) | ((z & ((uint64_t)1 << i)) << (2*i + 2));
	}
	return answer;
}


// VERSION WITH MAGIC BITS
// -----------------------
inline uint64_t splitBy3(int a){
	uint64_t x = a & 0x1fffff;
	x = (x | x << 32) & 0x1f00000000ffff;
	x = (x | x << 16) & 0x1f0000ff0000ff;
	x = (x | x << 8) & 0x100f00f00f00f00f;
	x = (x | x << 4) & 0x10c30c30c30c30c3;
	x = (x | x << 2) & 0x1249249249249249;
	return x;
}

inline uint64_t mortonEncode_magicbits(unsigned int x, unsigned int y, unsigned int z){
	uint64_t answer = 0;
	answer |= splitBy3(x) | splitBy3(y) << 1 | splitBy3(z) << 2;
	return answer;
}


// VERSION WITH LOOKUP TABLE
// -------------------------
static const uint32_t morton256_x[256] =
{
	0x00000000, 
	0x00000001, 0x00000008, 0x00000009, 0x00000040, 0x00000041, 0x00000048, 0x00000049, 0x00000200, 
	0x00000201, 0x00000208, 0x00000209, 0x00000240, 0x00000241, 0x00000248, 0x00000249, 0x00001000,<commit_msg>Removed trailing spaces<commit_after>#ifndef MORTON_H_
#define MORTON_H_

#include <stdint.h>
#include <limits.h>

using namespace std;

// encode a given (x,y,z) coordinate to a 64-bit morton code
inline uint64_t mortonEncode_for(unsigned int x, unsigned int y, unsigned int z); // slowest
inline uint64_t mortonEncode_magicbits(unsigned int x, unsigned int y, unsigned int z); // faster
inline uint64_t mortonEncode_LUT(unsigned int x, unsigned int y, unsigned int z); // fastest

// decode a given morton code into X,Y,Z coordinates
inline void mortonDecode_for(uint64_t morton, unsigned int& x, unsigned int& y, unsigned int& z); // slowest
inline unsigned int mortonDecode_magicbits_X(uint64_t morton); // faster
inline unsigned int mortonDecode_magicbits_Y(uint64_t morton);
inline unsigned int mortonDecode_magicbits_Z(uint64_t morton);

// VERSION WITH FOR LOOP
// ---------------------
inline uint64_t mortonEncode_for(unsigned int x, unsigned int y, unsigned int z){
	uint64_t answer = 0;
	for (uint64_t i = 0; i < (sizeof(uint64_t)* CHAR_BIT)/3; ++i) {
		answer |= ((x & ((uint64_t)1 << i)) << 2*i) | ((y & ((uint64_t)1 << i)) << (2*i + 1)) | ((z & ((uint64_t)1 << i)) << (2*i + 2));
	}
	return answer;
}

// VERSION WITH MAGIC BITS
// -----------------------
inline uint64_t splitBy3(int a){
	uint64_t x = a & 0x1fffff;
	x = (x | x << 32) & 0x1f00000000ffff;
	x = (x | x << 16) & 0x1f0000ff0000ff;
	x = (x | x << 8) & 0x100f00f00f00f00f;
	x = (x | x << 4) & 0x10c30c30c30c30c3;
	x = (x | x << 2) & 0x1249249249249249;
	return x;
}

inline uint64_t mortonEncode_magicbits(unsigned int x, unsigned int y, unsigned int z){
	uint64_t answer = 0;
	answer |= splitBy3(x) | splitBy3(y) << 1 | splitBy3(z) << 2;
	return answer;
}

// VERSION WITH LOOKUP TABLE
// -------------------------
static const uint32_t morton256_x[256] =
{
	0x00000000, 
	0x00000001, 0x00000008, 0x00000009, 0x00000040, 0x00000041, 0x00000048, 0x00000049, 0x00000200, 
	0x00000201, 0x00000208, 0x00000209, 0x00000240, 0x00000241, 0x00000248, 0x00000249, 0x00001000,
{'fraction_non_alphanumeric': 0.1568627450980392, 'fraction_numerical': 0.14068627450980392, 'mean_word_length': 3.8410438908659548, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 10, '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': '2307643', 'n_tokens_mistral': 1964, 'n_tokens_neox': 1551, 'n_words': 449}