Pajdeg  0.2.2
Pajdeg
PDStaticHash.h
Go to the documentation of this file.
1 //
2 // PDStaticHash.h
3 //
4 // Copyright (c) 2012 - 2015 Karl-Johan Alm (http://github.com/kallewoof)
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 // THE SOFTWARE.
23 //
24 
52 #ifndef INCLUDED_PDStaticHash_h
53 #define INCLUDED_PDStaticHash_h
54 
55 #include "PDDefines.h"
56 
66 #define static_hash_idx(mask, shift, key) (((long)key ^ ((long)key >> shift)) & mask)
67 
74 #define PDStaticHashIdx(stha, key) static_hash_idx(stha->mask, stha->shift, key)
75 
82 #define PDStaticHashValueForHash(stha, hash) stha->table[hash]
83 
90 #define PDStaticHashValueForKey(stha, key) stha->table[PDStaticHashIdx(stha, key)]
91 
99 #define PDStaticHashValueForHashAs(stha, hash, type) as(type, PDStaticHashValueForHash(stha, hash))
100 
108 #define PDStaticHashValueForKeyAs(stha, key, type) as(type, PDStaticHashValueForKey(stha, key))
109 
122 extern PDStaticHashRef PDStaticHashCreate(PDInteger entries, void **keys, void **values);
123 
131 extern void PDStaticHashDisownKeysValues(PDStaticHashRef sh, PDBool disownKeys, PDBool disownValues);
132 
133 // add key/value entry to a static hash; often expensive
134 //extern void PDStaticHashAdd(void *key, void *value);
135 
138 #endif
long PDInteger
Definition: PDDefines.h:184
unsigned char PDBool
Definition: PDDefines.h:207
void PDStaticHashDisownKeysValues(PDStaticHashRef sh, PDBool disownKeys, PDBool disownValues)
Definition: PDStaticHash.c:101
Definition: pd_internal.h:773
Definitions for the Pajdeg interface.
PDStaticHashRef PDStaticHashCreate(PDInteger entries, void **keys, void **values)
Definition: PDStaticHash.c:40