C++ map collision resolution as java HashMap -


I have already done a good and fast algorithm in Java that uses Howardmap.

  hashmap & lt; Point, float & gt; Map;   

Point class has the following structure

  Fixed public square point {Private IX; Private int y; Int hashCode () {int hash = 5; Hash = 59 * hash + it-> x; Hash = 59 * hash + THIS- & gt; Y; Return hash; } Boolean equivalent (point P) {return x == p. X & amp; Y == p .; }}   

I should repeat my algorithm in C ++ I decided to use c ++ stl hashmap.

I copied the point class with small changes according to the C ++ syntax, and wrote the map in the following manner:

  std :: map & lt; Example of using   

[/ code]

However, I have found that sometimes the C ++ version gives the wrong result of the algorithm after a lot of debugging , I found, some point equals hashodod:

  point (8,89) .hashcode () == 17 9 66; // x = 8, y = 89 points (930) .hashcode () == 17 9 66; Java resolves this conflict as a hash dispute solution with Hashmap Hashpe's similarity function, but I do not know how to implement it in C ++. Maybe I should write a better hash function, but I think this will not solve my problem completely, only remove some collisions, but will make new ones Can you help me?  

UPD:

The following code has been added to the point class:

  bool operator & lt; (Constant and RA) Cost {Return getX () & lt; Rhs.getX () || (Rhs.getX ()   

and declare as the following map:

  std :: map & lt; Point, float & gt; Mymap;   

and all start working

take a look On-depth_platform is a C ++ frame with a Java look and feel. It has been found in a Hashmap interface / behavior such as Java.

With this framework, a direct mapping can be implemented ...

  #include "cxx / lang / float.h" #include "cxx / use / Hashmap.cxx "using namespace CSS: Lung; Namespace CSS :: Usage; Square point: Public object {Private: int x; Int y; Public: Point (int x, int y): x (x), y (y) {} long hash code (zero) const {long hash = 5; Hash = 59 * hash + it-> x; Hash = 59 * hash + THIS- & gt; Y; Return hash; } Boolean equivalent (const object * obj) const {point * p = (dot *) obj; Return x == p- & gt; X & amp; Y == p-> Y; }}; Template class hashmap & lt; Point *, Float * & gt; Int main (int arzak, four ** argv) {hashmap> lieutenant; Point *, Float * & gt; Map; // add to (int i = 0; i <5; i ++) {point * p = new point (i, i); Float * f = new float (i); Map.put (p, f); } // find (int i = 0; i <5; i ++) {point p (i, i); If (map.get (& amp; p)! = Null) {// found}} return 0; }    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -