Comments (2)
You can have something like this (you would like to use a better hash function as pointers are not random):
#if UINTPTR_MAX == UINT64_MAX
static inline uint32_t hash_intptr(uintptr_t key) // by Thomas Wang
{
key = (~key) + (key << 18);
key = key ^ (key >> 31);
key = (key + (key << 2)) + (key << 4);
key = key ^ (key >> 11);
key = key + (key << 6);
key = key ^ (key >> 22);
return (uint32_t)key;
}
#else
static inline uint32_t hash_intptr(uintptr_t key)
{
key = ~key + (key << 15);
key = key ^ (key >> 12);
key = key + (key << 2);
key = key ^ (key >> 4);
key = (key + (key << 3)) + (key << 11);
key = key ^ (key >> 16);
return key;
}
#endif
#define my_hash_eq(a,b) ((a)==(b))
KHASH_INIT(name, uintptr_t, value_type, 1, hash_intptr, my_hash_eq)
Probably there are better ways to test the size of uintptr_t.
from klib.
Thanks. Actually my original question didn't make sense (I was thinking of applying hash and equals to values... eh!) It was relatively simple in the end.
In my header:
static const int StrPtr = 36;
KHASH_DECLARE(StrPtr, kh_cstr_t, uintptr_t)
In my source (note, I have removed static
from khash's SCOPE
to get things working; YMMV):
__KHASH_IMPL(StrPtr, kh_inline klib_unused, kh_cstr_t, uintptr_t, 1, kh_str_hash_func, kh_str_hash_equal)
And of course the khash instance is set up as:
khash_t(StrPtr) * devicesByName = kh_init(StrPtr);
And access is as all other examples. For now, this seems to be working. This issue can be closed.
from klib.
Related Issues (20)
- LICENSE file is missing HOT 4
- Hash signs in column converted into 'hash' on plot when using corr_plot HOT 1
- Potential crash: std::vector::resize and std::vector::reserve
- Difference kseq.h in klib and kseq.h in minimap2
- Easily copy/clone a khash hash table
- Crashes in KSON - kson_parse
- Don't pass type as named macro parameter HOT 3
- Ask for type less often
- Why is kbtree.h under BSD license?
- Create SECURITY.md
- khashl - Out of bounds memory read when querying an element not in hash table. HOT 1
- heapsort crash if input is empty
- Identify bug HOT 2
- Q: difference between khash.h and khashl.h HOT 1
- Radix Sort Implementation is not Stable HOT 2
- is this project still actively maintained or developed? HOT 1
- kv_resize to smaller doesn't set n
- Question: Can i use (khash) KHASH_SET_INIT_INT64() for negative values for key . Because i saw in khash header file its using unsigned long int please help me.
- implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1
- khashl.h - Massive increase in insertion time for large number of keys HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from klib.