<commit_before># -*- encoding: utf-8 -*-

"""
    stonemason.util.geo.hilbert
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Hilbert curve calculations.

Hilbert curve algorithms are taken from (and modified):
  <NAME>., Hakers's Delight Second Edition, 2012.
  Chapter 16: Hilbert's Curve
"""

__author__ = 'kotaimen'
__date__ = '1/9/15'

def hil_xy_from_s(unsigned long long s, int n):

    cdef int i
    cdef unsigned long long sa, sb
    cdef unsigned long long x, y, swap, cmpl
    cdef unsigned long long xp, yp

    x = 0
    y = 0

    for i in range(0, 2 * n, 2):
        sa = (s >> (i + 1)) & 1
        sb = (s >> i) & 1

        swap = (sa ^ sb) - 1
        cmpl = -(sa & sb)
        x = x ^ y
        y = y ^ (x & swap) ^ cmpl
        x = x ^ y

        x = (x >> 1) | (sa << 63)
        y = (y >> 1) | ((sa ^ sb) << 63)

    xp = x >> (64 - n)
    yp = y >> (64 - n)

    return xp, yp

def hil_s_from_xy(unsigned long long x, unsigned long long y, int n):
    cdef int i, xi, yi
    cdef unsigned long long s

    s = 0
    for i in range(n - 1, -1, -1):
        xi = (x >> i) & 1
        yi = (y >> i) & 1
        s = 4 * s + 2 * xi + (xi ^ yi)

        x = x ^ y
        y = y ^ (x & (yi - 1))
        x = x ^ y;

        x = x ^ (-xi & (yi - 1))
        y = y ^ (-xi & (yi - 1))

    return s
<commit_msg>TEST: Add assertions back to hilbert.pyx<commit_after># -*- encoding: utf-8 -*-

"""
    stonemason.util.geo.hilbert
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Hilbert curve calculations.

    Hilbert curve algorithms are taken from (and modified):
      <NAME>., Hakers's Delight Second Edition, 2012.
      Chapter 16: Hilbert's Curve
"""

__author__ = 'kotaimen'
__date__ = '1/9/15'

def hil_xy_from_s(unsigned long long s, int n):
    assert n < 64
    assert s < 4 ** n

    cdef int i
    cdef unsigned long long sa, sb
    cdef unsigned long long x, y, swap, cmpl
    cdef unsigned long long xp, yp

    x = 0
    y = 0

    for i in range(0, 2 * n, 2):
        sa = (s >> (i + 1)) & 1
        sb = (s >> i) & 1

        swap = (sa ^ sb) - 1
        cmpl = -(sa & sb)
        x = x ^ y
        y = y ^ (x & swap) ^ cmpl
        x = x ^ y

        x = (x >> 1) | (sa << 63)
        y = (y >> 1) | ((sa ^ sb) << 63)

    xp = x >> (64 - n)
    yp = y >> (64 - n)

    return xp, yp

def hil_s_from_xy(unsigned long long x, unsigned long long y, int n):
    assert n < 64

    cdef int i, xi, yi
    cdef unsigned long long s

    s = 0
    for i in range(n - 1, -1, -1):
        xi = (x >> i) & 1
        yi = (y >> i) & 1
        s = 4 * s + 2 * xi + (xi ^ yi)

        x = x ^ y
        y = y ^ (x & (yi - 1))
        x = x ^ y;

        x = x ^ (-xi & (yi - 1))
        y = y ^ (-xi & (yi - 1))

    return s

{'fraction_non_alphanumeric': 0.1670337738619677, 'fraction_numerical': 0.031938325991189426, 'mean_word_length': 1.5278293135435992, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3722805', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1039, 'n_words': 389}