This discussion is archived
7 Replies Latest reply: Apr 16, 2007 6:19 PM by 807606 RSS

HashMap (or similar) with size greater than 124?

807606 Newbie
Currently Being Moderated
I'm trying to create a collision checking method for my game. I have decided that the best way to do this is to use a map of some sort to store blocked pixels, but I found (the hard way) that hashmaps can only store 124 entries. The problem is, I need to be storing thousands (at least) of entries to the map. My error at this point (from the program's output) is this:
==Quote==
WARNING: A new instance of Collision has been made!
Adding 3100 pixels to the restricted pixel list for object button1.
Finished adding pixels to restricted pixel list for object button1.
Size of map now is 124
==End Quote==

So a single object is using 3100 entries but the 4% of the entries retained (for me at least) isn't quite enough :P
Is there some other method of data storage (with something similar to [boolean] containsKey) that I can use for this?
  • 1. Re: HashMap (or similar) with size greater than 124?
    807606 Newbie
    Currently Being Moderated
    but I found (the hard way) that hashmaps can only store 124 entries.
    How did you found that?
  • 2. Re: HashMap (or similar) with size greater than 124?
    807606 Newbie
    Currently Being Moderated
    but I found (the hard way) that hashmaps can only
    store 124 entries.
    Incorrect. HashMaps can hold millions of entries without any problems. You have a coding error.
  • 3. Re: HashMap (or similar) with size greater than 124?
    807606 Newbie
    Currently Being Moderated
    but I found (the hard way) that hashmaps can only
    store 124 entries.

    How did you found that?
    Er, the hard way.
  • 4. Re: HashMap (or similar) with size greater than 124?
    807606 Newbie
    Currently Being Moderated
    :-)
  • 5. Re: HashMap (or similar) with size greater than 124?
    807606 Newbie
    Currently Being Moderated
    but I found (the hard way) that hashmaps can
    only
    store 124 entries.

    How did you found that?
    Er, the hard way.
    I wonder why didn't he try by the simpler way. :sconf:
  • 6. Re: HashMap (or similar) with size greater than 124?
    796440 Guru
    Currently Being Moderated
    I'm trying to create a collision checking method for
    my game. I have decided that the best way to do this
    is to use a map of some sort to store blocked pixels,
    but I found (the hard way) that hashmaps can only
    store 124 entries.
    Incorrect. The theoretical limit is probably Integer.MAX_VALUE, or perhaps that squared, but the available memory of your computer will likely impose a much smaller limit (but far bigger than 124, unless your objects are monstrously huge).
  • 7. Re: HashMap (or similar) with size greater than 124?
    807606 Newbie
    Currently Being Moderated
    Oh, yes it is a programming error. I overlooks my addition method so thats my problem. So...

    I know that the code I'm using is supposed to go line after line and add each pixel to the hashmap, but it obviously isn't.

    This is the code I'm using, but I still don't know why it doesn't want to do what it should:
     //the CollsionStorage instance
        CollisionStorage cs = new CollisionStorage();
        
        /** 
         * Adds a restricted area.
         *
         *@param x The x location of the object (in pixels)
         *@param y The y location of the object (in pixels)
         *@param height The height of the object in pixels.
         *@param width The width of the object in pixels.
         *@param identifier A unique name to identifiy the object for logs.
         */
        public void addRestrictedArea(int x, int y, int height, int width, String identifier) {
         //The number of times to repeat = height * width (r=hw), so:
         int repeat = height * width;
         
         //the counters
         int hcounter = 0;
         int wcounter = 0;
         
         // The loop adds EVERY pixel defined by the args; the amount is determined by the repeat var.
         // Print some info
         System.out.println("Adding " + repeat + " pixels to the restricted pixel list for object " + identifier + ".");
         
         // The loop!
         for (int i = 0; hcounter <= height; i++) {
             if (wcounter == width) { // if the counter is = to the width, we are finished with the line and can move down one
              //reset counter
              wcounter = 0;
              // add to height counter
              hcounter++;
              
              //add the collision to storage
              cs.add(x, hcounter + y); 
              
              // raises the counter
              wcounter++;
             } else {
              // We know that we haven't finished the row because we got through the if, so we can keep going
              cs.add(wcounter+x, hcounter+y);
              wcounter++;
              
             }
         }
         //done- print message
         System.out.println("Finished adding pixels to restricted pixel list for object " + identifier + ".");
         System.out.println("Size of CS now is " + cs.badMoves.size());
        }
    Now all I'm wondering is why it isn't going through all of the pixels as methodicly as I had hoped...

    The code for CollisionStorage is at http://mazerunner.svn.sourceforge.net/viewvc/*checkout*/mazerunner/src/maps/utils/CollisionStorage.java
    All I'm storing in the map are 3 digit ints so I shouldn't have to worry about memory issues.