LibJuno 1.0.4
LibJuno is a lightweight C11 library designed specifically for embedded systems.
Loading...
Searching...
No Matches
hash_djb2.h
Go to the documentation of this file.
1/*
2 MIT License
3
4 Copyright (c) 2025 Robin A. Onsay
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files
8 (the "Software"), to deal in the Software without restriction,
9 including without limitation the rights to use, copy, modify, merge,
10 publish, distribute, sublicense, and/or sell copies of the Software,
11 and to permit persons to whom the Software is furnished to do so,
12 subject to the following conditions:
13
14 The above copyright notice and this permission notice shall be
15 included in all copies or substantial portions of the Software.
16*/
17
31#ifndef JUNO_HASH_DJB2_H
32#define JUNO_HASH_DJB2_H
33#include "juno/status.h"
34#include "juno/types.h"
35#ifdef __cplusplus
36extern "C"
37{
38#endif
39
40
47// @{"req": ["REQ-HASH-001", "REQ-HASH-002", "REQ-HASH-003"]}
48static inline JUNO_RESULT_SIZE_T JunoHash_Djb2(const uint8_t *pcBuff, size_t zBuffSize)
49{
50 JUNO_RESULT_SIZE_T tResult = {0, 0};
51 if(!(pcBuff))
52 {
53 tResult.tStatus = JUNO_STATUS_NULLPTR_ERROR;
54 return tResult;
55 }
56 size_t zHash = 5381;
57 for(size_t i = 0; i < zBuffSize; i++)
58 {
59 zHash = ((zHash << 5) + zHash) + pcBuff[i];
60 }
61 tResult.tStatus = JUNO_STATUS_SUCCESS;
62 tResult.tOk = zHash;
63 return tResult;
64}
65#ifdef __cplusplus
66}
67#endif
68#endif // JUNO_HASH_DJB2_H
69
#define JUNO_STATUS_NULLPTR_ERROR
A required pointer argument was NULL or invalid.
Definition status.h:63
#define JUNO_STATUS_SUCCESS
Operation completed successfully.
Definition status.h:59
static JUNO_RESULT_SIZE_T JunoHash_Djb2(const uint8_t *pcBuff, size_t zBuffSize)
Compute djb2 hash over a byte buffer.
Definition hash_djb2.h:48
Status codes and failure-handling helpers for LibJuno.
Common module result type aliases used throughout LibJuno.