-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split hashmap into .c and .h file (#451)
This fixes compilation warnings I had with `gcc` 8.5 using `-Wall`. Many of the static functions in `sundials_hashmap.h` were unused by files that included the header. After discussion with @balos1 moving the implementations into a .c file made more sense than adding the `inline` keyword to all the functions. --------- Co-authored-by: David Gardner <gardner48@llnl.gov> Co-authored-by: Cody Balos <balos1@llnl.gov>
- Loading branch information
1 parent
4989837
commit 6ce388b
Showing
5 changed files
with
76 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* ----------------------------------------------------------------- | ||
* Programmer: Cody J. Balos @ LLNL | ||
* ----------------------------------------------------------------- | ||
* SUNDIALS Copyright Start | ||
* Copyright (c) 2002-2024, Lawrence Livermore National Security | ||
* and Southern Methodist University. | ||
* All rights reserved. | ||
* | ||
* See the top-level LICENSE and NOTICE files for details. | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* SUNDIALS Copyright End | ||
* ----------------------------------------------------------------- | ||
* A simple hashmap implementation for char* keys and | ||
* void* values. Uses linear probing to resolve collisions. | ||
* The values can be anything, but will be freed by | ||
* the hash map upon its destruction. | ||
* -----------------------------------------------------------------*/ | ||
|
||
#ifndef _SUNDIALS_HASHMAP_IMPL_H | ||
#define _SUNDIALS_HASHMAP_IMPL_H | ||
|
||
#include <stdlib.h> | ||
#include <sundials/sundials_types.h> | ||
|
||
typedef struct SUNHashMapKeyValue_* SUNHashMapKeyValue; | ||
|
||
struct SUNHashMapKeyValue_ | ||
{ | ||
const char* key; | ||
void* value; | ||
}; | ||
|
||
typedef struct SUNHashMap_* SUNHashMap; | ||
|
||
struct SUNHashMap_ | ||
{ | ||
int size; /* current number of entries */ | ||
int max_size; /* max number of entries */ | ||
SUNHashMapKeyValue* buckets; | ||
}; | ||
|
||
SUNErrCode SUNHashMap_New(int max_size, SUNHashMap* map); | ||
SUNErrCode SUNHashMap_Destroy(SUNHashMap* map, void (*freevalue)(void* ptr)); | ||
int SUNHashMap_Iterate(SUNHashMap map, int start, | ||
int (*yieldfn)(int, SUNHashMapKeyValue, void*), void* ctx); | ||
int SUNHashMap_Insert(SUNHashMap map, const char* key, void* value); | ||
int SUNHashMap_GetValue(SUNHashMap map, const char* key, void** value); | ||
SUNErrCode SUNHashMap_Sort(SUNHashMap map, SUNHashMapKeyValue** sorted, | ||
int (*compar)(const void*, const void*)); | ||
|
||
#if SUNDIALS_MPI_ENABLED | ||
SUNErrCode SUNHashMap_Values(SUNHashMap map, void*** values, size_t value_size); | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters