<commit_before>// -*- Mode:C++ -*-

/**************************************************************************************************/
/*                                                                                                */
/* Copyright (C) 2015 University of Hull                                                          */
/*                                                                                                */
/**************************************************************************************************/
/*                                                                                                */
/*  module     :  glm/gtx/morton.inl                                                              */
/*  project    :                                                                                  */
/*  description:                                                                                  */
/*                                                                                                */
/**************************************************************************************************/

#if !defined(UKACHULLDCS_08961_GLM_GTX_MORTON_INL)

#define UKACHULLDCS_08961_GLM_GTX_MORTON_INL

// includes, system

//#include <>

// includes, project

//#include <>

#define UKACHULLDCS_USE_TRACE
#undef UKACHULLDCS_USE_TRACE
#include <support/trace.hpp>
#if defined(UKACHULLDCS_USE_TRACE) || defined(UKACHULLDCS_ALL_TRACE)
#  include <typeinfo>
#  include <support/type_info.hpp>
#endif

namespace glm {

  namespace morton {
    
    namespace detail {

      /*
       * [http://asgerhoedt.dk/?tag=morton-code]
       */
       
      template <unsigned N>
      inline unsigned
      compact_by(unsigned)
      {
        TRACE("glm::morton::detail::compact_by<N> (" + std::to_string(N) + ")");
        
        return unsigned(~0);
      }
      
      template <unsigned N>
      inline unsigned
      separate_by(unsigned)
      {
        TRACE("glm::morton::detail::separate_by<N> (" + std::to_string(N) + ")");
        
        return unsigned(~0);
      }

      template <>
      inline unsigned
      compact_by<0>(unsigned x)
      {
        TRACE("glm::morton::detail::compact_by<0>");
        
        return x;
      }
      
      template <>
      inline unsigned
      separate_by<0>(unsigned x)
      {
        TRACE("glm::morton::detail::separate_by<0>");
        
        return x;
      }

      template <>
      inline unsigned
      compact_by<1>(unsigned x)
      {
        TRACE("glm::morton::detail::compact_by<1>");
        
        x &= 0x55555555;                   // x = -f-e -d-c -b-a -9-8 -7-6 -5-4 -3-2 -1-0
        x  = (x ^ (x >>  1)) & 0x33333333; // x = --fe --dc --ba --98 --76 --54 --32 --10
        x  = (x ^ (x >>  2)) & 0x0f0f0f0f; // x = ---- fedc ---- ba98 ---- 7654 ---- 3210
        x  = (x ^ (x >>  4)) & 0x00ff00ff; // x = ---- ---- fedc ba98 ---- ---- 7654 3210
        x  = (x ^ (x >>  8)) & 0x0000ffff; // x = ---- ---- ---- ---- fedc ba98 7654 3210
        
        return x;
      }
      
      template <>
      inline unsigned
      separate_by<1>(unsigned x)
      {
        TRACE("glm::morton::detail::separate_by<1>");
        
        x &= 0x0000ffff;                   // x = ---- ---- ---- ---- fedc ba98 7654 3210
        x  = (x ^ (x <<  8)) & 0x00ff00ff; // x = ---- ---- fedc ba98 ---- ---- 7654 3210
        x  = (x ^ (x <<  4)) & 0x0f0f0f0f; // x = ---- fedc ---- ba98 ---- 7654 ---- 3210
        x  = (x ^ (x <<  2)) & 0x33333333; // x = --fe --dc --ba --98 --76 --54 --32 --10
        x  = (x ^ (x <<  1)) & 0x55555555; // x = -f-e -d-c -b-a -9-8 -7-6 -5-4 -3-2 -1-0

        return x;
      }

      template <>
      inline unsigned
      compact_by<2>(unsigned x)
      {
        TRACE("glm::morton::detail::compact_by<2>");

        x &= 0x49249249;                   // x = -a-- 9--8 --7- -6-- 5--4 --3- -2-- 1--0
        x  = (x ^ (x >>  2)) & 0x13033033; // x = -a-- --98 --7- -6-- --54 --3- -2-- --10
        x  = (x ^ (x >>  2)) & 0x0f00f00f; // x = ---- -a98 ---- ---- 7654 ---- ---- 3210
        x  = (x ^ (x >>  8)) & 0x000ff00f; // x = ---- ---- ---- -a98 7654 ---- ---- 3210
        x  = (x ^ (x >>  8)) & 0x000007ff; // x = ---- ---- ---- ---- ---- -a98 7654 3210
        
        return x;
      }
      
      template <>
      inline unsigned
      separate_by<2>(unsigned x)
      {
        TRACE("glm::morton::detail::separate_by<2>");

        x &= 0x000007ff;                   // x = ---- ---- ---- ---- ---- -a98 7654 3210
        x  = (x ^ (x <<  8)) & 0x000ff00f; // x = ---- ---- ---- -a98 7654 ---- ---- 3210
        x  = (x ^ (x <<  8)) & 0x0f00f00f; // x = ---- -a98 ---- ---- 7654 ---- ---- 3210
        x  = (x ^ (x <<  2)) & 0x13033033; // x = ---a --98 ---- --76 --54 ---- --32 --10
        x  = (x ^ (x <<  2)) & 0x49249249; // x = -a-- 9--8 --7- -6-- 5--4 --3- -2-- 1--0
        
        return x;
      }

      template <>
      inline unsigned
      compact_by<3>(unsigned x)
      {
        TRACE("glm::morton::detail::compact_by<3>");
        
        x &= 0x11111111;                   // x = ---7 ---6 ---5 ---4 ---3 ---2 ---1 ---0
        x  = (x ^ (x >>  3)) & 0x03030303; // x = ---- --76 ---- --54 ---- --32 ---- --10
        x  = (x ^ (x >>  6)) & 0x000f000f; // x = ---- ---- ---- 7654 ---- ---- ---- 3210
        x  = (x ^ (x >> 12)) & 0x000000ff; // x = ---- ---- ---- ---- ---- ---- 7654 3210
        
        return x;
      }
      
      template <>
      inline unsigned
      separate_by<3>(unsigned x)
      {
        TRACE("glm::morton::detail::separate_by<3>");

        x &= 0x000000ff;                   // x = ---- ---- ---- ---- ---- ---- 7654 3210
        x  = (x ^ (x << 12)) & 0x000f000f; // x = ---- ---- ---- 7654 ---- ---- ---- 3210
        x  = (x ^ (x <<  6)) & 0x03030303; // x = ---- --76 ---- --54 ---- --32 ---- --10
        x  = (x ^ (x <<  3)) & 0x11111111; // x = ---7 ---6 ---5 ---4 ---3 ---2 ---1 ---0
        <commit_msg>fixed: morton en/decode<commit_after>// -*- Mode:C++ -*-

/**************************************************************************************************/
/*                                                                                                */
/* Copyright (C) 2015 University of Hull                                                          */
/*                                                                                                */
/**************************************************************************************************/
/*                                                                                                */
/*  module     :  glm/gtx/morton.inl                                                              */
/*  project    :                                                                                  */
/*  description:                                                                                  */
/*                                                                                                */
/**************************************************************************************************/

#if !defined(UKACHULLDCS_08961_GLM_GTX_MORTON_INL)

#define UKACHULLDCS_08961_GLM_GTX_MORTON_INL

// includes, system

//#include <>

// includes, project

//#include <>

#define UKACHULLDCS_USE_TRACE
#undef UKACHULLDCS_USE_TRACE
#include <support/trace.hpp>
#if defined(UKACHULLDCS_USE_TRACE) || defined(UKACHULLDCS_ALL_TRACE)
#  include <typeinfo>
#  include <support/type_info.hpp>
#endif

namespace glm {

  namespace morton {
    
    namespace detail {

      /*
       * [http://asgerhoedt.dk/?tag=morton-code]
       */
       
      template <unsigned N>
      inline unsigned
      compact_by(unsigned)
      {
        TRACE("glm::morton::detail::compact_by<N> (" + std::to_string(N) + ")");
        
        return unsigned(~0);
      }
      
      template <unsigned N>
      inline unsigned
      separate_by(unsigned)
      {
        TRACE("glm::morton::detail::separate_by<N> (" + std::to_string(N) + ")");
        
        return unsigned(~0);
      }

      template <>
      inline unsigned
      compact_by<0>(unsigned x)
      {
        TRACE("glm::morton::detail::compact_by<0>");
        
        return x;
      }
      
      template <>
      inline unsigned
      separate_by<0>(unsigned x)
      {
        TRACE("glm::morton::detail::separate_by<0>");
        
        return x;
      }

      template <>
      inline unsigned
      compact_by<1>(unsigned x)
      {
        TRACE("glm::morton::detail::compact_by<1>");
        
        x &= 0x55555555;                   // x = -f-e -d-c -b-a -9-8 -7-6 -5-4 -3-2 -1-0
        x  = (x ^ (x >>  1)) & 0x33333333; // x = --fe --dc --ba --98 --76 --54 --32 --10
        x  = (x ^ (x >>  2)) & 0x0f0f0f0f; // x = ---- fedc ---- ba98 ---- 7654 ---- 3210
        x  = (x ^ (x >>  4)) & 0x00ff00ff; // x = ---- ---- fedc ba98 ---- ---- 7654 3210
        x  = (x ^ (x >>  8)) & 0x0000ffff; // x = ---- ---- ---- ---- fedc ba98 7654 3210
        
        return x;
      }
      
      template <>
      inline unsigned
      separate_by<1>(unsigned x)
      {
        TRACE("glm::morton::detail::separate_by<1>");
        
        x &= 0x0000ffff;                   // x = ---- ---- ---- ---- fedc ba98 7654 3210
        x  = (x ^ (x <<  8)) & 0x00ff00ff; // x = ---- ---- fedc ba98 ---- ---- 7654 3210
        x  = (x ^ (x <<  4)) & 0x0f0f0f0f; // x = ---- fedc ---- ba98 ---- 7654 ---- 3210
        x  = (x ^ (x <<  2)) & 0x33333333; // x = --fe --dc --ba --98 --76 --54 --32 --10
        x  = (x ^ (x <<  1)) & 0x55555555; // x = -f-e -d-c -b-a -9-8 -7-6 -5-4 -3-2 -1-0

        return x;
      }

      template <>
      inline unsigned
      compact_by<2>(unsigned x)
      {
        TRACE("glm::morton::detail::compact_by<2>");

        x &= 0x49249249;                   // x = -a-- 9--8 --7- -6-- 5--4 --3- -2-- 1--0
        x  = (x ^ (x >>  2)) & 0x430c30c3; // x = -a-- --98 ---- 76-- --54 ---- 32-- --10
        x  = (x ^ (x >>  4)) & 0x0f00f00f; // x = ---- -a98 ---- ---- 7654 ---- ---- 3210
        x  = (x ^ (x >>  8)) & 0x000ff00f; // x = ---- ---- ---- -a98 7654 ---- ---- 3210
        x  = (x ^ (x >>  8)) & 0x000007ff; // x = ---- ---- ---- ---- ---- -a98 7654 3210
        
        return x;
      }
      
      template <>
      inline unsigned
      separate_by<2>(unsigned x)
      {
        TRACE("glm::morton::detail::separate_by<2>");

        x &= 0x000007ff;                   // x = ---- ---- ---- ---- ---- -a98 7654 3210
        x  = (x ^ (x <<  8)) & 0x000ff00f; // x = ---- ---- ---- -a98 7654 ---- ---- 3210
        x  = (x ^ (x <<  8)) & 0x0f00f00f; // x = ---- -a98 ---- ---- 7654 ---- ---- 3210
        x  = (x ^ (x <<  4)) & 0x430c30c3; // x = -a-- --98 ---- 76-- --54 ---- 32-- --10
        x  = (x ^ (x <<  2)) & 0x49249249; // x = -a-- 9--8 --7- -6-- 5--4 --3- -2-- 1--0
        
        return x;
      }

      template <>
      inline unsigned
      compact_by<3>(unsigned x)
      {
        TRACE("glm::morton::detail::compact_by<3>");
        
        x &= 0x11111111;                   // x = ---7 ---6 ---5 ---4 ---3 ---2 ---1 ---0
        x  = (x ^ (x >>  3)) & 0x03030303; // x = ---- --76 ---- --54 ---- --32 ---- --10
        x  = (x ^ (x >>  6)) & 0x000f000f; // x = ---- ---- ---- 7654 ---- ---- ---- 3210
        x  = (x ^ (x >> 12)) & 0x000000ff; // x = ---- ---- ---- ---- ---- ---- 7654 3210
        
        return x;
      }
      
      template <>
      inline unsigned
      separate_by<3>(unsigned x)
      {
        TRACE("glm::morton::detail::separate_by<3>");

        x &= 0x000000ff;                   // x = ---- ---- ---- ---- ---- ---- 7654 3210
        x  = (x ^ (x << 12)) & 0x000f000f; // x = ---- ---- ---- 7654 ---- ---- ---- 3210
        x  = (x ^ (x <<  6)) & 0x03030303; // x = ---- --76 ---- --54 ---- --32 ---- --10
        x  = (x ^ (x <<  3)) & 0x11111111; // x = ---7 ---6 ---5 ---4 ---3 ---2 ---1 ---0
        
{'fraction_non_alphanumeric': 0.2554284767114205, 'fraction_numerical': 0.08652411735454997, 'mean_word_length': 0.9570223807979241, 'pattern_counts': {'":': 0, '<': 113, '<?xml version=': 0, '>': 113, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 12, 'word_list_counts': {'cursed_substrings.json': 52, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5179556', 'n_tokens_mistral': 4690, 'n_tokens_neox': 3801, 'n_words': 822}