Known size hash It is ok to call ImHashData on a string with known length but the ### operator won't be supported. FIXME-OPT: Replace with e.g. FNV1a hash? CRC32 pretty much randomly access 1KB. Need to do proper measurements.
| 2474 | // It is ok to call ImHashData on a string with known length but the ### operator won't be supported. |
| 2475 | // FIXME-OPT: Replace with e.g. FNV1a hash? CRC32 pretty much randomly access 1KB. Need to do proper measurements. |
| 2476 | ImGuiID ImHashData(const void* data_p, size_t data_size, ImGuiID seed) |
| 2477 | { |
| 2478 | ImU32 crc = ~seed; |
| 2479 | const unsigned char* data = (const unsigned char*)data_p; |
| 2480 | const unsigned char *data_end = (const unsigned char*)data_p + data_size; |
| 2481 | #ifndef IMGUI_ENABLE_SSE4_2_CRC |
| 2482 | const ImU32* crc32_lut = GCrc32LookupTable; |
| 2483 | while (data < data_end) |
| 2484 | crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ *data++]; |
| 2485 | return ~crc; |
| 2486 | #else |
| 2487 | while (data + 4 <= data_end) |
| 2488 | { |
| 2489 | crc = _mm_crc32_u32(crc, *(ImU32*)data); |
| 2490 | data += 4; |
| 2491 | } |
| 2492 | while (data < data_end) |
| 2493 | crc = _mm_crc32_u8(crc, *data++); |
| 2494 | return ~crc; |
| 2495 | #endif |
| 2496 | } |
| 2497 | |
| 2498 | // Zero-terminated string hash, with support for ### to reset back to seed value. |
| 2499 | // e.g. "label###id" outputs the same hash as "id" (and "label" is generally displayed by the UI functions) |
no outgoing calls
no test coverage detected