MCPcopy Create free account
hub / github.com/Overload-Technologies/Overload / ImHashStr

Function ImHashStr

Dependencies/ImGui/src/imgui.cpp:2501–2546  ·  view source on GitHub ↗

Zero-terminated string hash, with support for ### to reset back to seed value. e.g. "label###id" outputs the same hash as "id" (and "label" is generally displayed by the UI functions) FIXME-OPT: Replace with e.g. FNV1a hash? CRC32 pretty much randomly access 1KB. Need to do proper measurements.

Source from the content-addressed store, hash-verified

2499// e.g. "label###id" outputs the same hash as "id" (and "label" is generally displayed by the UI functions)
2500// FIXME-OPT: Replace with e.g. FNV1a hash? CRC32 pretty much randomly access 1KB. Need to do proper measurements.
2501ImGuiID ImHashStr(const char* data_p, size_t data_size, ImGuiID seed)
2502{
2503 seed = ~seed;
2504 ImU32 crc = seed;
2505 const unsigned char* data = (const unsigned char*)data_p;
2506#ifndef IMGUI_ENABLE_SSE4_2_CRC
2507 const ImU32* crc32_lut = GCrc32LookupTable;
2508#endif
2509 if (data_size != 0)
2510 {
2511 while (data_size-- > 0)
2512 {
2513 unsigned char c = *data++;
2514 if (c == '#' && data_size >= 2 && data[0] == '#' && data[1] == '#')
2515 {
2516 crc = seed;
2517 data += 2;
2518 data_size -= 2;
2519 continue;
2520 }
2521#ifndef IMGUI_ENABLE_SSE4_2_CRC
2522 crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
2523#else
2524 crc = _mm_crc32_u8(crc, c);
2525#endif
2526 }
2527 }
2528 else
2529 {
2530 while (unsigned char c = *data++)
2531 {
2532 if (c == '#' && data[0] == '#' && data[1] == '#')
2533 {
2534 crc = seed;
2535 data += 2;
2536 continue;
2537 }
2538#ifndef IMGUI_ENABLE_SSE4_2_CRC
2539 crc = (crc >> 8) ^ crc32_lut[(crc & 0xFF) ^ c];
2540#else
2541 crc = _mm_crc32_u8(crc, c);
2542#endif
2543 }
2544 }
2545 return ~crc;
2546}
2547
2548// Skip to the "###" marker if any. We don't skip past to match the behavior of GetID()
2549// FIXME-OPT: This is not designed to be optimal. Use with care.

Callers 15

ExecuteMethod · 0.85
TableOpenContextMenuMethod · 0.85
InitializeMethod · 0.85
ImGuiWindowMethod · 0.85
NewFrameMethod · 0.85
BeginChildExMethod · 0.85
FindWindowByNameMethod · 0.85
GetIDMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected