include/sfc.h
static unsigned hilbert_box_vtx_work(unsigned nDims, unsigned nBytes,
                                     unsigned nBits, int findMin, unsigned max,
                                     unsigned y, char *c1, char *c2,
                                     unsigned rotation, bitmask_t bits,
                                     bitmask_t index, BitReader getBits)
{
    bitmask_t const one = 1;
    bitmask_t const ndOnes = ones(bitmask_t, nDims);
    bitmask_t const nd1Ones = ndOnes >> 1;
    bitmask_t bitsFolded = 0;

    while(y--) {
        bitmask_t reflection = getBits(nDims, nBytes, c1, y);
        bitmask_t diff = reflection ^ getBits(nDims, nBytes, c2, y);
        if(diff) {
            unsigned d;
            bitmask_t smear = rotateRight(diff, rotation, nDims) >> 1;
            bitmask_t digit = rotateRight(bits ^ reflection, rotation, nDims);
            for(d = 1; d < nDims; d *= 2) {
                index ^= index >> d;
                digit ^= (digit >> d) & ~smear;
                smear |= smear >> d;
            }
            index &= 1;
            if((index ^ y ^ findMin) & 1)
                digit ^= smear + 1;
            digit = rotateLeft(digit, rotation, nDims) & diff;
            reflection ^= digit;

            for(d = 0; d < nDims; ++d)
                if(rdbit(diff, d)) {
                    int way = rdbit(digit, d);
                    char *target = d * nBytes + (way ? c1 : c2);
                    char *const source = 2 * d * nBytes + c1 - target + c2;
                    memcpy(target, source, nBytes);
                }

            bitsFolded |= diff;
            if(bitsFolded == ndOnes)
                return y;
        }

        bits ^= reflection;
        bits = rotateRight(bits, rotation, nDims);
        index ^= bits;
        reflection ^= one << rotation;
        adjust_rotation(rotation, nDims, bits);
        bits = reflection;
    }
    return y;
}
/*****************************************************************
 * hilbert_box_vtx
 *
 * Determine the first or last vertex of a box to lie on a Hilbert curve
 * Inputs:
 *  nDims:      Number of coordinates.
 *  nBytes:     Number of bytes/coordinate.
 *  nBits:      Number of bits/coordinate.
 *  findMin:    Is it the least vertex sought?
 *  coord1:     Array of nDims nBytes-byte coordinates - one corner of box
 *  coord2:     Array of nDims nBytes-byte coordinates - opposite corner
 * Output:
 *      c1 and c2 modified to refer to selected corner
 *      value returned is log2 of size of largest power-of-two-aligned box that
 *      contains the selected corner and no other corners
 * Assumptions:
 *      nBits <= (sizeof bitmask_t) * (bits_per_byte)
 */
hilbert_box_vtx
Determine the first or last vertex of a box to lie on a Hilbert curve
Inputs:
nDims:      Number of coordinates.
nBytes:     Number of bytes/coordinate.
nBits:      Number of bits/coordinate.
findMin:    Is it the least vertex sought.
hilbert_box_vtx Determine the first or last vertex of a box to lie on a Hilbert curve Inputs : nDims : Number of coordinates . nBytes : Number of bytes / coordinate . nBits : Number of bits / coordinate . findMin : Is it the least vertex sought .
static unsigned hilbert_box_vtx_work(unsigned nDims, unsigned nBytes,
                                     unsigned nBits, int findMin, unsigned max,
                                     unsigned y, char *c1, char *c2,
                                     unsigned rotation, bitmask_t bits,
                                     bitmask_t index, BitReader getBits)
{
    bitmask_t const one = 1;
    bitmask_t const ndOnes = ones(bitmask_t, nDims);
    bitmask_t const nd1Ones = ndOnes >> 1;
    bitmask_t bitsFolded = 0;
    while(y--) {
        bitmask_t reflection = getBits(nDims, nBytes, c1, y);
        bitmask_t diff = reflection ^ getBits(nDims, nBytes, c2, y);
        if(diff) {
            unsigned d;
            bitmask_t smear = rotateRight(diff, rotation, nDims) >> 1;
            bitmask_t digit = rotateRight(bits ^ reflection, rotation, nDims);
            for(d = 1; d < nDims; d *= 2) {
                index ^= index >> d;
                digit ^= (digit >> d) & ~smear;
                smear |= smear >> d;
            }
            index &= 1;
            if((index ^ y ^ findMin) & 1)
                digit ^= smear + 1;
            digit = rotateLeft(digit, rotation, nDims) & diff;
            reflection ^= digit;
            for(d = 0; d < nDims; ++d)
                if(rdbit(diff, d)) {
                    int way = rdbit(digit, d);
                    char *target = d * nBytes + (way ? c1 : c2);
                    char *const source = 2 * d * nBytes + c1 - target + c2;
                    memcpy(target, source, nBytes);
                }
            bitsFolded |= diff;
            if(bitsFolded == ndOnes)
                return y;
        }
        bits ^= reflection;
        bits = rotateRight(bits, rotation, nDims);
        index ^= bits;
        reflection ^= one << rotation;
        adjust_rotation(rotation, nDims, bits);
        bits = reflection;
    }
    return y;
}
static unsigned hilbert_box_vtx_work ( unsigned nDims , unsigned nBytes , unsigned nBits , int findMin , unsigned max , unsigned y , char * c1 , char * c2 , unsigned rotation , bitmask_t bits , bitmask_t index , BitReader getBits ) { bitmask_t const one = 1 ; bitmask_t const ndOnes = ones ( bitmask_t , nDims ) ; bitmask_t const nd1Ones = ndOnes >> 1 ; bitmask_t bitsFolded = 0 ; while ( y -- ) { bitmask_t reflection = getBits ( nDims , nBytes , c1 , y ) ; bitmask_t diff = reflection ^ getBits ( nDims , nBytes , c2 , y ) ; if ( diff ) { unsigned d ; bitmask_t smear = rotateRight ( diff , rotation , nDims ) >> 1 ; bitmask_t digit = rotateRight ( bits ^ reflection , rotation , nDims ) ; for ( d = 1 ; d < nDims ; d *= 2 ) { index ^= index >> d ; digit ^= ( digit >> d ) & ~ smear ; smear |= smear >> d ; } index &= 1 ; if ( ( index ^ y ^ findMin ) & 1 ) digit ^= smear + 1 ; digit = rotateLeft ( digit , rotation , nDims ) & diff ; reflection ^= digit ; for ( d = 0 ; d < nDims ; ++ d ) if ( rdbit ( diff , d ) ) { int way = rdbit ( digit , d ) ; char * target = d * nBytes + ( way ? c1 : c2 ) ; char * const source = 2 * d * nBytes + c1 - target + c2 ; memcpy ( target , source , nBytes ) ; } bitsFolded |= diff ; if ( bitsFolded == ndOnes ) return y ; } bits ^= reflection ; bits = rotateRight ( bits , rotation , nDims ) ; index ^= bits ; reflection ^= one << rotation ; adjust_rotation ( rotation , nDims , bits ) ; bits = reflection ; } return y ; }
hilbert_box_vtx
 Determine the first or last vertex of a box to lie on a Hilbert curve
 Inputs:
  nDims:      Number of coordinates.
hilbert_box_vtx Determine the first or last vertex of a box to lie on a Hilbert curve Inputs : nDims : Number of coordinates .