-1

Let's say I have a structure like this,

struct point3d{

  int x;

  int y;

  int z;

};

How can I create a hash value from this structure? Thanks

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
grayfox
  • 51
  • 4
  • Please review [the help pages](http://stackoverflow.com/help), especially ["What topics can I ask about here?"](http://stackoverflow.com/help/on-topic) and ["What types of questions should I avoid asking?"](http://stackoverflow.com/help/dont-ask). Also [take the tour](http://stackoverflow.com/tour) and [read about how to ask good questions](http://stackoverflow.com/help/how-to-ask) and [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Lastly don't forget how to create a [mcve]. – Some programmer dude Jan 22 '19 at 11:30
  • Reopened. The so-called dupe was for `std::size_t`, not for `int`. The latter has restrictions on overflow and bitwise shifting. – Bathsheba Jan 22 '19 at 11:33
  • What do you mean by "ordered int"? – Bathsheba Jan 22 '19 at 11:33
  • @MatthieuBrucher: Oops. Nobody's perfect. – Bathsheba Jan 22 '19 at 11:40
  • 1
    @Bathsheba No worries ;) – Matthieu Brucher Jan 22 '19 at 11:44

1 Answers1

-1

A lot depends on what you want to achieve and how much distribution you need.

Most non-cryptographic hash would be similar to :

int64_t Hash(const point3d & point){
       int64_t start = 1234; //magic number
       int64_t multiplier = 3467; //some other magic number
       int64_t hash = start + point.x;
       hash = hash*multiplier + point.y;
       hash = hash * multiplier + point.z;
       return hash;

}

Test this out on your data set by tuning start and multiplier.

bashrc
  • 4,725
  • 1
  • 22
  • 49