star-hitran

Load line-by-line data from the HITRAN database
git clone git://git.meso-star.fr/star-hitran.git
Log | Files | Refs | README | LICENSE

commit 221c7acf396077e3f3f86ea6dd1d503b155c6aba
parent 743df20e734aa65bbde9ec1e80b7b0421396f45c
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Mon,  9 Mar 2026 21:43:34 +0100

Add a function that computes the hash of a list of lines

Diffstat:
Msrc/shtr.h | 5+++++
Msrc/shtr_line_list.c | 34++++++++++++++++++++++++++++++++++
2 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/src/shtr.h b/src/shtr.h @@ -380,6 +380,11 @@ shtr_line_list_get_info (const struct shtr_line_list* list, struct shtr_line_list_info* info); +SHTR_API res_T +shtr_line_list_hash + (const struct shtr_line_list* list, + hash256_T hash); + END_DECLS #endif /* SHTR_H */ diff --git a/src/shtr_line_list.c b/src/shtr_line_list.c @@ -514,6 +514,22 @@ error: } static void +hash_blocks(const struct shtr_line_list* list, struct sha256_ctx* ctx) +{ + size_t i = 0; + size_t n = 0; + ASSERT(list && ctx); + + n = darray_charp_size_get(&list->blocks); + FOR_EACH(i, 0, n) { + const char* block = darray_charp_cdata_get(&list->blocks)[i]; + const size_t nlines = MMIN(NLINES_PER_BLOCK, nlines - i*NLINES_PER_BLOCK); + + sha256_ctx_update(ctx, block, nlines*sizeof(struct line)); + } +} + +static void release_lines(ref_T * ref) { struct shtr* shtr = NULL; @@ -783,3 +799,21 @@ shtr_line_list_get_info *info = list->info; return RES_OK; } + +res_T +shtr_line_list_hash(const struct shtr_line_list* list, hash256_T hash) +{ + struct sha256_ctx ctx; + res_T res = RES_OK; + + if(!list || !hash) { res = RES_BAD_ARG; goto error; } + + sha256_ctx_init(&ctx); + hash_blocks(list, &ctx); + sha256_ctx_finalize(&ctx, hash); + +exit: + return res; +error: + goto exit; +}