Float Arrays and hashcodes

Hi,
I have some problems with generating unique hash codes for float arrays.
The following code will result in "true" on my JVM (JRE 1.6):
System.out.println(Arrays.hashCode(new float[]{0,1,2,3,6,9}) == Arrays.hashCode(new float[]{0,1,3,6,8,9}));Does anyone have an idea how to generate a truly unique hashcode for float arrays?
Thanks for your help,
Dieter

JoachimSauer wrote:
dkleinrath wrote:
JoachimSauer wrote:
But again: you don't usually need a perfect hash. Why do you think you need one?I use static HashMaps to store meta information about specific arrays. I also use a HashSet to search for unique arrays in a big collection of arrays.That's ok. Both HashMap and HashSet can work perfectly with in-perfect hash code (obviously, since perfect hash codes are not possible in many situations).
What they can not handle is .equals() being "wrong" (i.e. inconsistent with hashCode()).
This means that you can't directly use float[] as keys.
You could build a simple wrapper around float[] to be used as keys, 'though.I just tried that and it works like a charm.
Thank you very much for your help.

Similar Messages

  • Dynamically create empty mcs and asign elements from array and loadmovie

    I'm creating an educational game for my school students.
    A little boy is flying through the city when he encounters objects flying from left to right.
    He hears a SOUND eg: Dog - he must go and click the dog image with the flying cursor. There are at least 5 DIFFERENT objects that should be flying on the screen. There could be various of them at any one time.
    I have the roots of the images in an xml file. And the actual swf are in a file called IMAGE and the sounds in SOUND.
    My problem is that most tutorials I see use the attachmovie method but I don't want to put all the swf's in the library as there are hundreds.
    I have to use the loadmovie method.
    I take it I have to loop through the array and assign each element to an empty movieclip which in turn is in the loop so you get 5 empty clips - I will use i (index). It doesn't seem to be working. I shall keep trying and post back here if I get any luck but I'm running out of ideas.
    Then the objects have to float across the screen. Don't know whether to use tween object or onEnterFrame handler or other. AND someone has mentioned using setinterval to "spit out" the objects.
    BUT if I have five flying across the screen I'm left without clips to stick in any more.
    Oh my head hurts but I will keep going.
    CHEERS if any help is around. This should be quite a standard thng for game developpers. Code at the moment
    function loadEnemies():Void {
    enemy_xml = new XML();
    enemy_xml.ignoreWhite = true;
    enemy_xml.onLoad = function(success:Boolean) {
    if (success) {
    _root.parseEnemyXML();
    //enemy_xml.load("level_"+level+".xml");
    enemy_xml.load("data/animal_catch.xml");
    function parseEnemyXML():Void {
    rows = enemy_xml.firstChild.childNodes.length;
    for (var i:Number = 0; i<rows; i++) {
    var row_string:String = String(enemy_xml.firstChild.childNodes[i].firstChild.firstChild);
    _root["row_"+i+"_array"] = row_string; //MAIN ARRAY holds an array images/dog_a.swf/ images/cat_a.swf etc... all five
    _root.createEmptyMovieClip("enemyObjects", 1);
    enemyObjects.createEmptyMovieClip("holder_"+i, i);
    _root["object"+i] = new Sound(enemyObjects["holder_"+i]);
    trace(row_string);
    loadMovie["row_"+i+"_array"], ["holder_"+i]
    if (level == 1) {
    alerts_mc.play();
    } else {
    currRow = 0;
    rowCounter = 0;
    OK got to about here BUT
    a. I started to get confused around the createEmptyMovieClip part
    b. I KNOW I shouldn't have Sound(enemyObjetcs etc... BUT I copied the code from a tutorial and I don't know what to replace it with.
    I'm close but I need a little polishing.

    It doesn't do you much good to work with borrowed code that you do not understand.  Your best bet will be to start small, creating one functional piece of the puzzle at a time, and work your way up.  Start with making sure you are loading and parsing the xml properly, then set about loading the external content, then see about making that content move around, etc...
    In the code you show, your loadMovie line of code does not resemble anything I have seen before, looking more like (but not quite like) a multi-dimensional array element than a loadMovie() function call.  If you find you need to have control of the items as soon as they load, then you should consider using MovieClipLoader.loadClip instead of loadMovie.  The MovieClipLoader class provides features, such as to be able to determine when items have fully loaded.

  • Inserting Records in an Array and using a constructor with it

    I badly need help on this! Please please please! I have been studying java for a short time only.
    Anyway, here goes: My project requires the following:
    Employee inputs the no. of video in the shelf. They have four classifications: Drama, Comedy, Action, and Thriller. Each video classification has different rates. The employee creates a video record containing the following information: 1. video ID number, 2. video classification, and 3. Price.
    The employee should display the classifications of videos available and the price. Only the available video tapes would be displayed according to the customer's chosen classification. When the customer chooses the video he wants to rent, the program will register and attach the name of the customer to the video number.
    I only need to use arrays, and NOT database to record the information.

    is it ok i i declare the drama_rate outside the video class?
    i have a list of variables on my videoupdate classYes. It's probably best to declare it static & then you can access it directly:
    public static float drama_rate = 100.0;
    rate = <the class name>.drama_rate;
    so, i should also include a customer no. both in the video and customer class.I would. You may want to list a bunch of videos and who currently has them. This way you don't have to search the customers AND the videos to do this.
    thanks =) i don't know either why we had to validate/invalidate,\
    but our applet doesnt refresh when >it is supposed to, so
    we just used this method. It wouldnt slow down the application, would it?Could you just revalidate()?
    the use of arrays. i havent finished with the program yet.
    i have the design already, i just couldnt put it in code.
    im not familiar with the use of multidimensional arrays-
    can i use this for the video and customer records i will need to store?Not sure what you're using arrays for, but here's an example of something I might do. Maybe it will be useful to you.
    Have you looked at HashMaps? You could use "Customer" as the key and then use an ArrayList of checked out Videos as the value:
    HashMap customers = new HashMap();
    ArrayList videos = new ArrayList();
    //Add the checked out videos to the list
    videos.add(video);
    <etc>
    // Add this customer and the list of videos he has checked out.
    customers.put(customer,videos);
    [\code]

  • Create an image from float array?

    Dear All,
    I have a float array containing pixel values. From that array I want to create an image (let's say in JPEG format).
    How should I do that?
    thanks

    Hi musti168,
    You're going through your entire image pixel-by-pixel and getting each of their values - why don't you just use the IMAQ ImageToArray function?  
    On this forum post I found an example of IMAQ ArrayToImage: http://forums.ni.com/t5/LabVIEW/IMAQ-arraytoimage-​example/td-p/68418
    You can use some of the IMAQ Image Processing palette to change the image to gray scale - possibly a threshold.
    Julian R.
    Applications Engineer
    National Instruments

  • Converting strings to the floating number and plotting

    Hello,
    I have a question regardting converting string of numbers to the floating bumbers and plot for voltage vs. weight.
    The load cell for the ADC resolution is 16 bits, and the voltage will be in between +-5 volts.
    The problem, I have the most is converting the string of numbers to the floating numbers, in my case is the weight.
    Attachments:
    tunnelv1.vi ‏139 KB

    When you say "string of numbers" do you mean an array? What is the specific issue you are having? You seem to have orange wires running all over the place. Give a small example demonstrating the problem.
    Mike...
    Certified Professional Instructor
    Certified LabVIEW Architect
    LabVIEW Champion
    "... after all, He's not a tame lion..."
    Be thinking ahead and mark your dance card for NI Week 2015 now: TS 6139 - Object Oriented First Steps

  • Programatic control of float array precision?

    Using LV6.1, I can't figure out how to control the array precision similar to the attached example's control of a simple float control.  Can it be done?
    Attachments:
    Untitled.vi ‏20 KB

    Hi RAMaston,
    you can create a property node of the numeric element in the Array not from the entire array. Select the single numeric element in the array and create the property of it in the same way like the property of the other numeric indicator.
    Mike
    Message Edited by MikeS81 on 03-19-2008 02:34 PM

  • How to store (non-persistent) multiple float[] arrays.

    Hi;
    In a situation where an object needs to store multiple float arrays, how can I use a 2 dimensional array to store them? I can't use a collection since an array is a primitive.
    I would use a 2 dimensional array, but my keys to get/set these arrays are ints. So I cant do a "int i[][]", nor a "float f[][]".
    Any ideas?
    Thanks;
    -nat

    You could make a Map (such as HashMap) with an
    Integer (java.lang.Integer) key and a "int []" or "float []" as a value (an array is an Object, so can be put as a value).You kid me not! I need to review my basics.
    I simply didn't know that an array of primitives can be stored as a value in a map.
    Thank you!
    -nat

  • Converting float array to Float array

    Hi, is there any efficent way to convert float[][] to Float[][] without iterating the array and creating Float object for each float data? I have a method performing calculations based on a 2D array( float[][]) and then need to store the result in a TreeMap data structure. The "put" method for TreeMap ask Object type.
    Thanks in advance!

    1) No
    2) An array of float is an object as well:
    Object obj = new float[]{1.0, 2.0, 3.0};3) What you want to store? If your structure is somewhat like this:
    float[][] f = {
       { 1.0, 2.0, 3.0 },
       { 4.0, 5.0, 6.0 },
    };and you want to "index" your TreeMap by the first element of each row of your float[] array, you could do something like this:
        SortedMap sm = new TreeMap();
        sm.put(new Float(f[0][0]), f[0]); // Arrays are objects as well
        sm.put(new Float(f[1][0]), f[1]); //and so on.

  • How to make VIs as "Fp Read (Float Array -IO)" available to take a measurement?

    I can't succeed in launching a fieldpoint VI cause I don't find the VI FP Read (Float Array -IO).vi. If I have well understood these VIs (like FP Open and other) are made available when installing the Field Point Server. In my case nothing occurs. What can I do?
    thanks.

    Hello,
    If you have the FieldPoint drivers installed in the computer where you are opening this VI, then you should find the FP Read.VI on the functions palette of the Block Diagram (right click on any open space of the block diagram => All function => NI Measurements => FieldPoint)
    If this VI that you can't find is actually a subVI that was made by the person that made the program, just save it from where it was developed and copy it on the new computer.
    If this is unclear or if you have any more questions, please let me know.
    Regards,
    LA

  • How to read binary file into a 2D float array??

    Hi All,
    I really need help to get this one as I am stuck and can't seem to find any way out of it. I am given a '.dat' file that has float values in it. I want to read this file in java and put it in a 2D float array. The file has basically a matrix of float values. What I want to do is to read this binary file and put all its data into 2D float array (float [] []) so that I can use it in my program. Is there a way to read file like this? I did find a similar matlab code (below) but cant seem to find anything in java and i really want to do this in java only.. I will appreciate ur help in this one.
    thanks very much
    Nitya
    fid = fopen('datafile.dat');
    A = fread(fid,[50 50],'float32');
    fclose(fid);

    I shud have shown the two ways that i Already tried. here they are..
    first one using DataInputStream and then trying to readFloat()
    DataInputStream dis = ....
    Float f = dis.readFloat();This code gives code gives me some random values like this.. (i had a loop)
    5.8758974E-14
    -0.41055492
    1.5724557E-30
    1.06822824E14
    -1.91934371E15
    3.43829601E13
    Other way i tried was this.. which seems right but here i have to convert byte to float and i thnk that code is giving some different results (slightly different float values) not sure why....may be my indexing of the array is wrong to make it a matrix.. or something else...
    is.read(bytes, offset....);
    int cnt = 0;
    int j = 0;
    for (int start = 0; start < offset; start = start + 4) {
      if(j<50){
           myarray[cnt][j] = this.arr2float(bytes, start);
             System.out.println(cnt + "-" + j + " = " + myarray[cnt][j]);
           j++;
    }else{
      if(cnt < 50){
           cnt++;
           j = 0;
      }else{
           break;
    public float arr2float (byte[] arr, int start) {
              int i = 0;
              int len = 4;
              int cnt = 0;
              byte[] tmp = new byte[len];
              for (i = start; i < (start + len); i++) {
                   tmp[cnt] = arr;
                   cnt++;
              int accum = 0;
              i = 0;
              for ( int shiftBy = 0; shiftBy < 32; shiftBy += 8 ) {
                   accum |= ( (long)( tmp[i] & 0xff ) ) << shiftBy;
                   i++;
              return Float.intBitsToFloat(accum);
    Not sure if i am missing some other way to do this...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to split the blob byte array and insert in oracle

    how to split the blob byte array and insert in oracle
    I am having a string which is of more than lenght 4000 so i am using BLOB datatype as input to get the string.
    need to split the blob in oracle and store in the different column
    The string is of bytearray i need to strore it in each column based on the byte array.

    this will be my input i need to split the above and store it in different columns in a table.
    for spliting say
    Column1 -1 byte
    Column2-3 byte
    Column3-5 byte
    ColumnN-5 byte
    Table will have corresponding data type
    Column1 - number(10,2)
    Column2 - Float
    Column3 - Float
    ColumnN-Float
    here Column2 datatype is float but it will always have 3 byte information.
    where as Column3 datatype is also float but it will always have 5 byte information.
    Say N is Column 120

  • How do I convet C Float array to Java Float Array.

    Hi All,
    I am using some C function in the JNI which will return Float array.
    How do I convert the Float C array elements to jfloatArray elemets. And my native method implementation should return jfloatArray.
    If any one of you have the sample code please send reply.
    regards
    Ravi Kumar

    to return the c array to jfloat array do the following:
    ur function should have a return type of jfloat
    this is for c++::
    jfloatArray ret = (jfloatArray)env->NewFloatArray(length of the array);
    env->SetFloatArrayRegion(ret,index,number of retunrs,jfloat *);
    for c u just have to include the env variable
    jfloatArray ret = (jfloatArray)env->NewFloatArray(env,length of the array);
    return ret;
    this will work when u give the array indexes properly.
    regards
    vidhya

  • Missing FP READ (Float Array-IO).vi & FP WRITE (Float Array-IO).vi

    I am a complete newbie. I am trying to use the Field Point Express vi to collect data from some Field Point modules. When I go to past the Field Point Express VI into my sheet, the applications starts looking for a couple of sub-vi's. It is missing the FP Read (Float Array-IO).vi and the FP Write (Float Array-IO).vi. I am not sure if I erased these accidentally or what. Is there a way to replace these missing VIs?

    These vi's are usually located in C:\Program Files\National Instruments\LabVIEW XX\vi.lib\FieldPoint\Polymorphic Read.llb. First, check if they are present and try to manually link them when the LV is trying to load them. Otherwise, you can try to uninstall your FP drivers and then perform a re-install. The FieldPoint drivers are located in your Device Drivers CD.
    Hope this helps.

  • FP Read (Float Array -IO).vi request

    Whenever I use the FieldPoint palette item under Input or Output I get a message asking for FP Read (Float Array -IO).vi and then FP Write (Float Array -IO).vi This vi is not present anywhere on my harddrive and a search of this website came up with nothing. The Fieldpoint palette item does not work properly when I choose Cancel - the input or output value becomes an integer (I think) that does not actually read or write data. What is this error, and how do I fix it?

    The VIs that are missing should be in the ...LabVIEW\vi.lib\FieldPoint\Polymorphic Read.llb and ...LabVIEW\vi.lib\FieldPoint\Polymorphic Write.llb files. If you are missing them, it is likely that your installation has become corrupted. You can copy the above files from a different computer or re-install the NI-FieldPoint driver.
    Regards,
    Aaron

  • Floating fields and fragment subforms in Outlook 2007 do not display correctly

    I'm using LCES Forms 8.0 Update 1 to render a non-interactive HTML forms using dynamic content (customer info). The email appears ok in clients except in Outlook 2007.
    The Floating text and Text Fields appear multiple times on the form (scattered around their placement point on the form) and the subform fragments are appearing with borders surrounding them.
    I have heard that there are issues with Outlook 2007 not displaying HTML correctly. Is there a way to setup the Text Fields/Subforms in Designer so they display correctly in Outlook 2007?
    Thanks!

    Create a new profile as a test to check if your current profile is causing the problems.
    See "Basic Troubleshooting: Make a new profile":
    *https://support.mozilla.org/kb/Basic+Troubleshooting#w_8-make-a-new-profile
    There may be extensions and plugins installed by default in a new profile, so check that in "Tools > Add-ons > Extensions & Plugins" in case there are still problems.
    If the new profile works then you can transfer some files from the old profile to that new profile, but be careful not to copy corrupted files.
    See:
    *http://kb.mozillazine.org/Transferring_data_to_a_new_profile_-_Firefox

Maybe you are looking for