#version 3.8; global_settings { assumed_gamma 1.0 } #macro bitwise_rightshift (Number, Places) #local Divisor = pow (2, Places); #local Bitshifted_Result = Number / Divisor; Bitshifted_Result #end #macro bitwise_leftshift (Number, Places) #local Multiplier = pow (2, Places); #local Bitshifted_Result = Number * Multiplier; Bitshifted_Result #end #macro get16bits (Value) #local Result = bitwise_leftshift (Value, 8) + Value; Result #end #macro SuperFastHash (data, len) // should be a 32-bit result #local hash = len; #if (len <= 0) #local hash = 0; #else #local rem = bitwise_and (len, 3); #local len = bitwise_rightshift (len, 2); // Main loop #for (loop, len, 0, -1) #local hash = hash + get16bits (data); #local tmp = bitwise_xor (bitwise_leftshift (get16bits (data+2), 11), hash); #local hash = bitwise_xor (bitwise_leftshift (hash, 16), tmp); #local data = data + 2*16; // 2*sizeof (uint16_t); #local hash = hash + bitwise_rightshift (hash, 11); #end // end for // Handle end cases #switch (rem) #case (3) #local hash = hash + get16bits (data); #local hash = bitwise_xor (bitwise_leftshift (hash, 16), hash); #local hash = bitwise_xor (bitwise_leftshift (data, 18), hash); #local hash = hash + bitwise_rightshift (hash, 11); #break #case (2) #local hash = hash + get16bits (data); #local hash = bitwise_xor (bitwise_leftshift (hash, 11), hash); #local hash = hash + bitwise_rightshift (hash, 17); #break #case (1) #local hash = hash + data; #local hash = bitwise_xor (bitwise_leftshift (hash, 10), hash); #local hash = hash + bitwise_rightshift (hash, 1); #break #end // end switch case // Force "avalanching" of final 127 bits #local hash = bitwise_xor (bitwise_leftshift (hash, 3), hash); #local hash = hash + bitwise_rightshift (hash, 5); #local hash = bitwise_xor (bitwise_leftshift (hash, 4), hash); #local hash = hash + bitwise_rightshift (hash, 17); #local hash = bitwise_xor (bitwise_leftshift (hash, 25), hash); #local hash = hash + bitwise_rightshift (hash, 16); #end hash #end // end macro SuperFastHash #for (i, 1, 50) #debug concat ("Input: ", str (i, 10, 0), " hash: ", str (SuperFastHash (i, 10), 10, 0), "\n") #end #debug concat ("i: ", str (i, 10, 0), "\n") #error "No objects in scene" /* #include "pstdint.h" //Replace with if appropriate #undef get16bits #if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \ || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__) #define get16bits(d) (*((const uint16_t *) (d))) #endif #if !defined (get16bits) #define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8)\ +(uint32_t)(((const uint8_t *)(d))[0]) ) #endif uint32_t SuperFastHash (const char * data, int len) { uint32_t hash = len, tmp; int rem; if (len <= 0 || data == NULL) return 0; rem = len & 3; len >>= 2; //Main loop for (;len > 0; len--) { hash += get16bits (data); tmp = (get16bits (data+2) << 11) ^ hash; hash = (hash << 16) ^ tmp; data += 2*sizeof (uint16_t); hash += hash >> 11; } //Handle end cases switch (rem) { case 3: hash += get16bits (data); hash ^= hash << 16; hash ^= ((signed char)data[sizeof (uint16_t)]) << 18; hash += hash >> 11; break; case 2: hash += get16bits (data); hash ^= hash << 11; hash += hash >> 17; break; case 1: hash += (signed char)*data; hash ^= hash << 10; hash += hash >> 1; } // Force "avalanching" of final 127 bits hash ^= hash << 3; hash += hash >> 5; hash ^= hash << 4; hash += hash >> 17; hash ^= hash << 25; hash += hash >> 6; return hash; } */ /* bitwise_and(A,B,...) Bitwise AND of two or more float values considered as integers. bitwise_or(A,B,...) Bitwise OR of two or more float values considered as integers. bitwise_xor(A,B,...) Bitwise XOR of two or more float values considered as integers. Note: For the three bit-wise functions, each parameter is first converted to integer (so fractional part is ignored), and the computation is performed on a classical int. Do not expect to much precision, as conversion from a double precision number (usually with 52 bits mantissa) to an integer and back to a double precision number is not the best way to keep track of every bit. */