Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4096844
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:05:54+00:00 2026-05-20T20:05:54+00:00

This question is related to this one but I think should be asked separately.

  • 0

This question is related to this one but I think should be asked separately.

I have a complex graph of object instances. Now I would like to create a checksum on this object graph directly in memory to detect whether changes have been made to it since the last time the checksum was saved with the object graph. The checksum calculation should be quick and should not consume too much memory.

As I understand now the best solution would probably be to generate a cryptographic key on a binary serialized form of the object graph (correct me if I am wrong). But that comes with a few questions:

  1. How should I serialize the object? It must be fast and not
    consume too much memory. Also it
    must reliably always be serialized
    the same way. If I use the .NET default serialization can I really be sure that the created binary stream is always the same if the actual data is the same? I doubt it.
  2. So what would be an alternative way to serialize that doesn’t take to long to implement?

Update:

What do you think about this approach:

  1. navigate through the graph and
    foreach object in the graph create a
    standard int hashcode using
    this algorithm (but exclude reference type members representing nodes in the graph). Add each
    hashcode to a integer list
  2. convert the integer list to a byte
    array
  3. create a hash on the byte array
    using MD5, CRC or similar

The GetHashCode algorithm mentioned should quickly calculate a hashcode that is pretty collision safe for a single object that only takes its primitive members into account. Based on this the byte array should also be a pretty collision safe representation of the object graph and the MD5/CRC hash on this too.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T20:05:54+00:00Added an answer on May 20, 2026 at 8:05 pm

    What do you think about this approach:

    • navigate through the graph and foreach object in the graph create a standard int hashcode using this algorithm (but exclude reference type members representing nodes in the graph).
    • Add each hashcode to a integer list
    • Convert the integer list to a byte array
    • Create a hash on the byte array using MD5, CRC or similar

    This approach idea is quite near to what I ‘d consider best, but it could use some polishing.

    Hashing

    Considering that you would prefer speed over accuracy and that an int-sized hashcode for each item leaves plenty of room for avoiding collissions, the choice of hashcode algo seems right. Excluding reference types that participate in the graph means we ‘re throwing some information away; see below for more on that.

    Improving the node hash

    The idea of not taking into account other nodes connected to the node we are hashing is correct, but maybe we can do better than simply throwing all that information away? We don’t want to take the hashcodes of other nodes into account (they will be hashed themselves as well), but we are throwing away the information provided by the graph edges here: the hashcode for a node with internal data X connected to N other nodes should not be the same for a node with data X connected to M other nodes.

    If you have a cheap way of using a part of the edge data into account, use it. For example, if the graph is directed then you can add to the hashcode computed for each node the number of edges going out from it to other nodes.

    Aggregating hashcodes

    Creating a list of hashcodes would be the middle-ground approach between summing the hashcodes in one long (very fast and keeps some additional information over summing into an int) and creating a list of hashcodes dependent on a total order of the items in the graph. If you expect lots of items in the graph then summing might be more appropriate (I ‘d try that first and see if it’s collision-free enough); if the graph doesn’t have many items (say < 1000) then I ‘d try the total-order approach first. Remember to allocate enough memory for the list (or simply use an array) when creating it; you already know its final length so that’s a free speed increase.

    Producing a fixed-size hash

    If you have summed the hashcodes into a primitive, this step is not required at all. Otherwise, hashing the list as a byte[] is what I ‘d consider best. Since hashing the bytes will take very little time in comparison to creating the list, you may want to use a larger-sized hash function than md5 or crc32 to reduce collisions without a practical performance hit.

    Improving the final hash quality

    After getting this “final” hash, I ‘d prepend or append to it the number of items in the hashed graph as fixed-size hex-encoded string because:

    • It might help in reducing collisions (how much depends on the nature of the graphs)
    • We already know the number of items in the graph (we just hashed each one of them) so it’s an O(1) operation

    Defining a total order

    If the order in which the items in the graph are processed is not strictly defined, then the door is open for false negatives: two graphs which should hash to the same value do not because even though they are logically equivalent, the implementation of the hash function chose to process the per-item hashes in a different order. This problem will appear only if you use a list, since addition is transitive so the “add into a long approach” is immune to it.

    To combat that, you need to process the nodes in the graph in a well-defined order. That might be an order that’s easy to produce from the data structure of the nodes (e.g. like preorder traversal on a tree) and/or other information (e.g. class names or node types for each node, node ids if such exist etc).

    Since preprocessing the graph to produce a total order is going to take some time, you may want to weigh that against the cost incurred by a false negative result as I mentioned above. Also, if the graphs are large enough then this discussion might be moot because of the node hashcode summation approach being more suited to your needs.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a general question on how Features should be created when we have
Recently I had a question on the interview - I was asked to compare
I am pretty much worried to make a duplicate with this question while more
I'm doing a Java project where I have to make a text similarity program.
I have a Git repository on my local machine that I cloned from my
As an experiment I’ve been toying with an idea of creating an IIS managed
I recently dove headfirst into a project that uses nHibernate heavily. I've gotten a
I'm working on a sketch search engine that correlates whatever someone's sketching with a
We are using Subversion and TortoiseSVN. We use the trunk for development and branches

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.