xref: /petsc/include/petsc/private/hashmapiv.h (revision 970231d20df44f79b27787157e39d441e79f434b)
1 #pragma once
2 
3 #include <petsc/private/hashmap.h>
4 
5 /* SUBMANSEC = Sys */
6 /*
7    Hash map from PetscInt --> PetscScalar
8 */
9 PETSC_HASH_MAP(HMapIV, PetscInt, PetscScalar, PetscHashInt, PetscHashEqual, -1)
10 
11 /*MC
12   PetscHMapIVAddValue - Add value to the value of a given key if the key exists,
13   otherwise, insert a new (key,value) entry in the hash table
14 
15   Synopsis:
16   #include <petsc/private/hashmapiv.h>
17   PetscErrorCode PetscHMapIVAddValue(PetscHMapT ht,PetscInt key,PetscScalar val)
18 
19   Input Parameters:
20 + ht  - The hash table
21 . key - The key
22 - val - The value
23 
24   Level: developer
25 
26 .seealso: `PetscHMapIVGet()`, `PetscHMapIVIterSet()`, `PetscHMapIVSet()`
27 M*/
PetscHMapIVAddValue(PetscHMapIV ht,PetscInt key,PetscScalar val)28 static inline PetscErrorCode PetscHMapIVAddValue(PetscHMapIV ht, PetscInt key, PetscScalar val)
29 {
30   int      ret;
31   khiter_t iter;
32 
33   PetscFunctionBeginHot;
34   PetscAssertPointer(ht, 1);
35   iter = kh_put(HMapIV, ht, key, &ret);
36   PetscHashAssert(ret >= 0);
37   if (ret) kh_val(ht, iter) = val;
38   else kh_val(ht, iter) += val;
39   PetscFunctionReturn(PETSC_SUCCESS);
40 }
41