1
0
Fork 0

Added: Gazoo-specific ID

Browse Source
This commit is contained in:
rhuibertsjr 2024-06-04 15:31:35 +02:00
parent 3f555be7b5
commit deebd0eaa8
5 changed files with 73 additions and 21 deletions

View File

@ -32,6 +32,9 @@ typedef uint64_t b64;
#define MIN(A,B) (((A)<(B))?(A):(B))
#define STRINGIFY_(S) #S
#define STRINGIFY(S) STRINGIFY_(S)
#define array_count(a) (sizeof(a) / sizeof((a)[0]))
//= rhjr: linked-list

View File

@ -3,14 +3,7 @@ internal Key
hash_store_hash(String8 data)
{
Key result = {0};
u64 hash = 5381;
for(u64 i = 0; i < data.length; i += 1)
{
hash = ((hash << 5) + hash) + data.content[i];
}
memory_copy(&result, &hash, sizeof(u64));
blake2b((u8*) &result.U16[0], sizeof(u32), data.content, data.length, 0, 0);
return result;
}
@ -23,7 +16,7 @@ hash_store_initialize(void)
Table *table = arena_push(arena, Table);
table->arena = arena;
table->str8_arena = str8_arena;
table->slots_count = 200;
table->slots_count = 230;
table->slots = arena_push_array(arena, TableSlot, table->slots_count);
@ -34,7 +27,7 @@ internal Key
hash_store_string8_to_key(Table *table, String8 data)
{
Key result = hash_store_hash(data);
u64 slot_idx = result.U32[0]%table->slots_count;
u64 slot_idx = result.U16[0]%table->slots_count;
TableNode *node = arena_push(table->arena, TableNode);
node->data.content = arena_push_array(table->str8_arena, char, data.length);
@ -54,12 +47,12 @@ internal String8
hash_store_string8_from_key(Table *table, Key key)
{
String8 result = {0};
u64 slot_idx = key.U32[0]%table->slots_count;
u64 slot_idx = key.U16[0]%table->slots_count;
TableSlot *slot = &table->slots[slot_idx];
for (TableNode *n = slot->first; n != 0; n = n->next)
{
if (key.U32[1] == n->key.U32[1])
if (key.U16[1] == n->key.U16[1])
{
result = n->data;
break;

View File

@ -1,10 +1,16 @@
#ifndef HASH_TABLE_H
#define HASH_TABLE_H
#if !defined(BLAKE2_H)
#define HAVE_SSE2
#include "thirdparty/blake2/blake2.h"
#include "thirdparty/blake2/blake2b.c"
#endif
typedef struct Key Key;
struct Key
{
u32 U32[2];
u16 U16[2];
};
typedef struct TableNode TableNode;

View File

@ -13,7 +13,10 @@ internal String8 keywords[] = {
str8_lit_comp("precondities"),
str8_lit_comp("product configuratie"),
str8_lit_comp("toestand"),
//...
str8_lit_comp("luchtwasser pH"),
str8_lit_comp("luchtwasser EC"),
str8_lit_comp("luchtwasser spuiteller"),
//- rhjr: testcase procedure
str8_lit_comp("testprocedure"),
@ -25,21 +28,68 @@ internal String8 keywords[] = {
str8_lit_comp("luchtwasser vultijd"),
str8_lit_comp("luchtwasser sproeiklep"),
str8_lit_comp("luchtwasser wasserpomp"),
str8_lit_comp("luchtwasser spuiklep"),
str8_lit_comp("spuitijd teller"),
//- rhjr: acties
str8_lit_comp("luchtwasser"),
str8_lit_comp("maximale-vlotter"),
str8_lit_comp("minimale-vlotter"),
str8_lit_comp("verhoog"),
//- rhjr: values
str8_lit_comp("wassen"),
str8_lit_comp("vullen"),
str8_lit_comp("spuien"),
str8_lit_comp("start"),
str8_lit_comp("open"),
str8_lit_comp("dicht"),
str8_lit_comp("aan"),
str8_lit_comp("uit")
str8_lit_comp("uit"),
//- rhjr: unique
str8_lit_comp("luchtwasser EC spui-waarde"),
str8_lit_comp("luchtwasser maximale spuitijd")
};
typedef enum {
TESTCASE = 0xF8E8,
IDENTIFICATIECODE = 0x78b0,
TITEL = 0x98d2,
BESCHRIJVING = 0x19fd,
PRECONDITIES = 0x91fb,
PRODUCT_CONFIGURATIE = 0xf925,
TOESTAND = 0xcfd8,
LUCHTWASSER_PH = 0x543f,
LUCHTWASSER_EC = 0x031a,
LUCHTWASSER_SPUITELLER = 0xadae,
TESTPROCEDURE = 0x614f,
LUCHTWASSER_VENTILATOR = 0x70e6,
LUCHTWASSER_WATERKLEP = 0xa991,
LUCHTWASSER_TOESTAND = 0x63f8,
LUCHTWASSER_VULTIJD = 0xb6db,
LUCHTWASSER_SPROEIKLEP = 0x39f5,
LUCHTWASSER_WASSERPOMP = 0x159f,
LUCHTWASSER_SPUIKLEP = 0x93d1,
SPUITIJD_TELLER = 0xdaf9,
LUCHTWASSER = 0x0529,
MAXIMALE_VLOTTER = 0xa318,
MINIMALE_VLOTTER = 0xab74,
VERHOOG = 0x4e7d,
WASSEN = 0xfbcb,
VULLEN = 0xa2c3,
SPUIEN = 0xbe62,
START = 0xf5b3,
OPEN = 0x1690,
DICHT = 0x9be6,
AAN = 0x5f2e,
UIT = 0x6fe8,
LUCHTWASSER_EC_SPUI_WAARDE = 0x996a,
LUCHTWASSER_MAXIMALE_SPUITIJD = 0xbacb,
} Translation;
#endif

View File

@ -18,15 +18,15 @@ main(void)
for (u64 idx = 0; idx < list_size; idx += 1)
{
if (string8_match(keywords[idx], str8_lit("luchtwasser toestand"))){
int x = 0;
}
Key key = hash_store_string8_to_key(table, keywords[idx]);
String8 string = hash_store_string8_from_key(table, key);
printf("%.*s\n", (i32) string.length, string.content);
printf("str8 arena: %lld - arena %lld\n", table->str8_arena->current->offset, table->arena->current->offset);
Translation trans = key.U16[0];
printf("%.*s =\t %04x - %04x - %u\n",
(i32) string.length, string.content, key.U16[0], trans,
((key.U16[0] == trans) ? 1 : 0)
);
}
return 0;