mirror of
https://github.com/jarun/nnn.git
synced 2025-01-15 13:26:37 +00:00
icons-hash: some minor cleanups
This commit is contained in:
parent
aab5ab53a5
commit
63a254951d
|
@ -12,21 +12,23 @@
|
|||
|
||||
#ifdef ICONS_GENERATE
|
||||
|
||||
#define ICONS_PROBE_MAX_ALLOWED 6
|
||||
#define ICONS_MATCH_MAX ((size_t)-1)
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include "icons.h"
|
||||
|
||||
#ifdef NDEBUG
|
||||
#error "NDEBUG"
|
||||
#endif
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "icons.h"
|
||||
|
||||
#define ASSERT(X) assert(X)
|
||||
#define ARRLEN(X) (sizeof(X) / sizeof((X)[0]))
|
||||
#define MAX(A, B) ((A) > (B) ? (A) : (B))
|
||||
#define HGEN_ITERARATION (1ul << 14)
|
||||
#define ICONS_PROBE_MAX_ALLOWED 6
|
||||
#define ICONS_MATCH_MAX ((size_t)-1)
|
||||
|
||||
#if 0 /* enable for debugging */
|
||||
#define log(...) fprintf(stderr, "[INFO]: " __VA_ARGS__)
|
||||
#else
|
||||
|
@ -133,19 +135,9 @@ main(void)
|
|||
assert(found);
|
||||
}
|
||||
|
||||
log("hash_start: %u\n", (unsigned)hash_start);
|
||||
log("hash_mul : %u\n", (unsigned)hash_mul);
|
||||
log("max_probe : %u\n", max_probe);
|
||||
|
||||
printf("#ifndef INCLUDE_ICONS_GENERATED\n");
|
||||
printf("#define INCLUDE_ICONS_GENERATED\n\n");
|
||||
|
||||
printf("/*\n * NOTE: This file is automatically generated.\n");
|
||||
printf(" * DO NOT EDIT THIS FILE DIRECTLY.\n");
|
||||
printf(" * Use `icons.h` to customize icons\n */\n\n");
|
||||
|
||||
printf("#define hash_start %uu\n", hash_start);
|
||||
printf("#define hash_mul %uu\n\n", hash_mul);
|
||||
log("hash_start: %6u\n", (unsigned)hash_start);
|
||||
log("hash_mul : %6u\n", (unsigned)hash_mul);
|
||||
log("max_probe : %6u\n", max_probe);
|
||||
|
||||
size_t match_max = 0, icon_max = 0;
|
||||
for (size_t i = 0; i < ARRLEN(icons_name); ++i) {
|
||||
|
@ -160,6 +152,15 @@ main(void)
|
|||
icon_max = MAX(icon_max, strlen(exec_icon.icon) + 1);
|
||||
icon_max = MAX(icon_max, strlen(file_icon.icon) + 1);
|
||||
|
||||
printf("#ifndef INCLUDE_ICONS_GENERATED\n");
|
||||
printf("#define INCLUDE_ICONS_GENERATED\n\n");
|
||||
|
||||
printf("/*\n * NOTE: This file is automatically generated.\n");
|
||||
printf(" * DO NOT EDIT THIS FILE DIRECTLY.\n");
|
||||
printf(" * Use `icons.h` to customize icons\n */\n\n");
|
||||
|
||||
printf("#define hash_start %uu\n", hash_start);
|
||||
printf("#define hash_mul %uu\n\n", hash_mul);
|
||||
printf("#define ICONS_PROBE_MAX %u\n", max_probe);
|
||||
printf("#define ICONS_MATCH_MAX %zuu\n\n", match_max);
|
||||
|
||||
|
@ -190,13 +191,13 @@ main(void)
|
|||
static uint16_t
|
||||
icon_ext_hash(const char *str)
|
||||
{
|
||||
const unsigned int z = 16 - ICONS_TABLE_SIZE; /* 16 == size of `hash` in bits */
|
||||
uint16_t hash = hash_start;
|
||||
for (size_t i = 0; i < ICONS_MATCH_MAX && str[i] != '\0'; ++i) {
|
||||
hash ^= TOUPPER((unsigned char)str[i]) + i;
|
||||
uint32_t i, hash = hash_start;
|
||||
const unsigned int z = (sizeof hash * CHAR_BIT) - ICONS_TABLE_SIZE;
|
||||
for (i = 0; i < ICONS_MATCH_MAX && str[i] != '\0'; ++i) {
|
||||
hash ^= TOUPPER((unsigned char)str[i]);
|
||||
hash *= hash_mul;
|
||||
}
|
||||
hash = (hash >> z) ^ hash;
|
||||
hash ^= (hash >> z);
|
||||
hash *= GOLDEN_RATIO_16;
|
||||
hash >>= z;
|
||||
ASSERT(hash < ARRLEN(table));
|
||||
|
|
Loading…
Reference in a new issue