Thread overview | |||||
---|---|---|---|---|---|
|
May 29, 2016 How to hash any type to an integer? | ||||
---|---|---|---|---|
| ||||
I'm currently implementing a hash map as an exercise and wondered if there is a built-in function I could use to hash keys effectively? What I'm looking for is a function that hashes any variable (of any type) to an integer. I've been looking at the `getHash` function of the `TypeInfo` class but that only seems to return the passed pointer. Any ideas? |
May 29, 2016 Re: How to hash any type to an integer? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gary Willoughby | On Sunday, 29 May 2016 at 11:05:21 UTC, Gary Willoughby wrote: > I'm currently implementing a hash map as an exercise and wondered if there is a built-in function I could use to hash keys effectively? What I'm looking for is a function that hashes any variable (of any type) to an integer. > > I've been looking at the `getHash` function of the `TypeInfo` class but that only seems to return the passed pointer. Any ideas? How about hashOf? https://dlang.org/phobos/object.html#.hashOf |
May 30, 2016 Re: How to hash any type to an integer? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Seb | On Sunday, 29 May 2016 at 16:26:58 UTC, Seb wrote:
> On Sunday, 29 May 2016 at 11:05:21 UTC, Gary Willoughby wrote:
>> I'm currently implementing a hash map as an exercise and wondered if there is a built-in function I could use to hash keys effectively? What I'm looking for is a function that hashes any variable (of any type) to an integer.
>>
>> I've been looking at the `getHash` function of the `TypeInfo` class but that only seems to return the passed pointer. Any ideas?
>
> How about hashOf?
> https://dlang.org/phobos/object.html#.hashOf
Awesome, thanks. Can't believe I missed that.
|
Copyright © 1999-2021 by the D Language Foundation