www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Why can't or shouldn't I just hash the address of an object? And how.

reply Enjoys Math <enjoysmath gmail.com> writes:
I am creating a custom graph database for our app. It holds not 
one huge graph but a collection of independent graphs.  I would 
like to be able to delete them without looping through a range of 
billions of Graph class references.

How can I accomplish this with an AA and hasing?

Is it:

typeof(T).getHash(&o)?

Or does that do something other than just get the address?

Is this a bad idea for an App communities main content server?
Dec 29 2018
parent reply Neia Neutuladh <neia ikeran.org> writes:
On Sun, 30 Dec 2018 05:36:41 +0000, Enjoys Math wrote:
 Is it:
 
 typeof(T).getHash(&o)?
This gets the hashcode for the object by calling toHash() on it.
 Or does that do something other than just get the address?
It XORs the address with a bitwise rotation of the address. This reduces collisions since objects are allocated aligned. As for your larger problem, I'd strongly tend toward using a database to hold application state instead of keeping it in memory.
Dec 29 2018
parent Enjoys Math <enjoysmath gmail.com> writes:
On Sunday, 30 December 2018 at 05:54:05 UTC, Neia Neutuladh wrote:
 On Sun, 30 Dec 2018 05:36:41 +0000, Enjoys Math wrote:
 Is it:
 
 typeof(T).getHash(&o)?
This gets the hashcode for the object by calling toHash() on it.
 Or does that do something other than just get the address?
It XORs the address with a bitwise rotation of the address. This reduces collisions since objects are allocated aligned. As for your larger problem, I'd strongly tend toward using a database to hold application state instead of keeping it in memory.
Thanks, mon! :D I have decided to use long databaseID's everywhere, so that will fix that issue. I can key an AA easily by a long. I am building the database myself, I already evaluated each graph database out there, and for some reasons or others they don't suit our needs. So I'm doing a very custom database, not one I can re-use or distribute. It's just for commutative diagrams (in math) and my app called ZoomSpace. It is really fun to code this thing. I am making it super efficient by doing the label matching with a Trie (my regexes are very simple).
Dec 30 2018