static unsigned int refhash(naRef key) { if(IS_STR(key)) { struct naStr* s = PTR(key).str; if(s->hashcode) return s->hashcode; return s->hashcode = hash32((void*)naStr_data(key), naStr_len(key)); } else { /* must be a number */ union { double d; unsigned int u[2]; } n; n.d = key.num == -0.0 ? 0.0 : key.num; /* remember negative zero! */ return mix32(mix32(n.u[0]) ^ n.u[1]); } }
static unsigned int hash32(const unsigned char* in, int len) { unsigned int h = len, val = 0; int i, count = 0; for(i=0; i<len; i++) { val = (val<<8) ^ in[i]; if(++count == 4) { h = mix32(h ^ val); val = count = 0; } } return mix32(h ^ val); }
Color4f TextureSource::get_texel( TextureCache& texture_cache, const size_t ix, const size_t iy) const { assert(ix >= 0); assert(iy >= 0); assert(ix < m_texture_props.m_canvas_width); assert(iy < m_texture_props.m_canvas_height); // Compute the coordinates of the tile containing the texel (x, y). const size_t tile_x = truncate<size_t>(ix * m_texture_props.m_rcp_tile_width); const size_t tile_y = truncate<size_t>(iy * m_texture_props.m_rcp_tile_height); assert(tile_x < m_texture_props.m_tile_count_x); assert(tile_y < m_texture_props.m_tile_count_y); #ifdef DEBUG_DISPLAY_TEXTURE_TILES return integer_to_color( mix32( static_cast<uint32>(m_assembly_uid), static_cast<uint32>(m_texture_index), static_cast<uint32>(tile_x), static_cast<uint32>(tile_y))); #endif // Compute the tile space coordinates of the texel (x, y). const size_t pixel_x = ix - tile_x * m_texture_props.m_tile_width; const size_t pixel_y = iy - tile_y * m_texture_props.m_tile_height; assert(pixel_x < m_texture_props.m_tile_width); assert(pixel_y < m_texture_props.m_tile_height); // Sample the tile. Color4f sample; sample_tile( texture_cache, m_assembly_uid, m_texture_index, tile_x, tile_y, pixel_x, pixel_y, sample); return sample; }
static inline uint64_t final64(uint64_t h) { h += (h << 3); h ^= (h >> 23); h += (h << 34); return h; } // // public // uint32_t strhash32(uint32_t h, const char * restrict s) { while(*s) h = mix32(h, *s); return final32(h); } uint32_t hash32(uint32_t h, const void * const restrict v, size_t l) { const char * s = v; size_t x; for(x = 0; x < l; x++) h = mix32(h, s[x]); return final32(h); }