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