LibJuno 1.0.1
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
47static inline JUNO_RESULT_SIZE_T JunoHash_Djb2(const uint8_t *pcBuff, size_t zBuffSize)
48{
49 JUNO_RESULT_SIZE_T tResult = {0, 0};
50 if(!(pcBuff))
51 {
52 tResult.tStatus = JUNO_STATUS_NULLPTR_ERROR;
53 return tResult;
54 }
55 size_t zHash = 5381;
56 for(size_t i = 0; i < zBuffSize; i++)
57 {
58 zHash = ((zHash << 5) + zHash) + pcBuff[i];
59 }
60 tResult.tStatus = JUNO_STATUS_SUCCESS;
61 tResult.tOk = zHash;
62 return tResult;
63}
64#ifdef __cplusplus
65}
66#endif
67#endif // JUNO_HASH_DJB2_H
68
#define JUNO_STATUS_NULLPTR_ERROR
A required pointer argument was NULL or invalid.
Definition status.h:60
#define JUNO_STATUS_SUCCESS
Operation completed successfully.
Definition status.h:56
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:47
Status codes and failure-handling helpers for LibJuno.
Common module result type aliases used throughout LibJuno.