Using byte[] as a key in a concurrent dictionary.

Hi All,
I have created a Concurrent Dictionary with key as a object containing byte array using IEqualityComparer. I was wondering how do I create a hash code for each such object when adding to my dictionay. I tried below creating hash code using sum of all
the bytes present in the byte array of the object, but the performance is worst when we try to compare with normal dictionary with some existing data type as a key. Please suggest how do I improve performance of my dictionary with custom key(object with byte
array).
Thanks and Regards,
Lucas

Calculating the hash of a large byte array can be more expensive than handling hash collisions.  So perhaps use your special knowledge about the data to extract a few bytes from the array to use in the hash.
eg
public int GetHashCode(byte[] obj)
if (obj == null)
return -1;
if (obj.Length == 0)
return 0;
if (obj.Length < 64)
return obj.Length * obj[1];
var fp = new byte[4];
fp[0] = obj[0];
fp[1] = obj[16];
fp[2] = obj[27];
fp[3] = obj[55];
return obj.Length ^ BitConverter.ToInt32(fp, 0);
David
David http://blogs.msdn.com/b/dbrowne/

Similar Messages

  • Using NUMBER as a key

    I need to create an index organized "mean and lean" table with very high cardinality (~ 1B recs). The table will consist of 1 or 2 columns of type NUMBER, plus a foreign key generated by a sequence. I need a "mean and lean" data type to use for the foreign key.
    After understanding the true nature of NUMBER, I resist using that data type. Compared to using a true binary integer, it'll be longer, variable in length and might even have to be translated to binary before it can be used correctly in a B-Tree sort. Oracle apparently does not support true binary integers, my preferred choice.
    Since only C/SQL programs will load the DB, I'm considering using a CHAR(x) data type (a true, static length field) and stuffing it with real binary integer data. In a sense, I'll be forcing a CHAR(x) type to be a binary int.
    Q: Am I wrong in assessing NUMBER as a poor choice for an index?
    Q: Can anyone forsee problems in using the CHAR(x) approach?
    Q: Will Oracle cough on the unprintable characters I will try to store in CHAR(x)?
    Q: Will this be a more efficient data type to use for an index?

    And the answer is....
    ORACLE really give you no choice. NUMBER is the only way to store integers. You can use words like INTEGER and LONG and SHORT in the "Create Table" command, but those all just translate to NUMBER. Trying to stuff true binary numbers in CHAR(x) doesn't work either, probably because many of them are unprintables and RDBMS won't accept that. Storing true binary values in RAW isn't much better than NUMBER because it's got a 1-2 byte "string length" header attached to it (much like NUMBER).
    Bottom line is that ORACLE does not support true binary integer types and it prevents you from using the potentially workaround of CHAR(x) by rejecting unprintables. Other binary types have string length prefixes which defeat the purpose of having minimally sized binary fields for storage.
    If you want to get true binary integers into an ORACLE database, buy Oracle RDB.

  • I used to be able to skip a cell to the right by using the toggle arrow keys

    I placing a number or text in a cell i used to be able to skip the cell to the right by using the toggle arrow keys.  I can't now?  Using the RETURN key only goes down a cell.  I want to go right?  Why?

    Hi Mark,
    In Numbers 3, an arrow key moves the cursor one cell up, down, left or right.
    Tab moves one cell right. Shift tab moves one cell left.
    The command key and an arrow key will take the cursor to top, bottom, left or right of a table.
    via the arrow keys (next to the letterM and question mark?).
    I am puzzled by this. Between the letter M and ? I have < above comma (,) and > above full stop (.)
    Shift command < zooms out and shift command > zooms in.
    Regards,
    Ian.

  • How can I copy a webpage that will not let me highlight it, i.e. use the control c key strokes?

    How can I take a picture of a webpage that will not let me use the control C copy command? In other words, on this particular website, I try to highlight a passage that I want to save and put in a document, but the highlighting will not work. I asked them about that, and they simply said they did not have that facility, but I think the issue is protecting their copyrighted material. I know there is some way to take a picture of the page, and then I can use my picture editing software to crop it and enlarge it.

    Are you trying to take a "snapshot" in a PDF?
    If the part of the page or PDF you want to capture is fully visible, you can use the Windows print screen function to capture it. Either use the Print Screen key to capture the entire monitor display, or Alt+Print Screen to capture the active window.
    If you need to do this often, or if you want to save the snapshot straight to disk, or if you need more than fits in a single Windows screen shot, an add-on such as [https://addons.mozilla.org/en-us/firefox/addon/fireshot/ Fireshot] can be handy.

  • Error when using byte array in web service model interface

    Hello everybody,
    I'm using a web service model in my web dynpro application. The web service requires a byte array as import parameter.
    When starting the web dynpro application the following error occurs:
    com.sap.tc.webdynpro.services.exceptions.WDTypeNotFoundException: type java:byte not found
    at com.sap.tc.webdynpro.services.datatypes.core.DataTypeBroker.getDataType(DataTypeBroker.java:216)
    I'm using byte arrays several times in my application --> no problem. So why does the error say "byte not found" when using the web service?
    Thanks for your help!
    regards
    Christian

    Hi,
    maybe this is the problem. The type is byte and not binary.
    But I have the same problem as mentioned in the other thread: I can't change the type.
    The type in the WSDL of my web service is "base64binary". Is there maybe a possibility to import a jar-file for this type?
    Christian

  • We have several licences of Adobe Photoshop Elements V9 can we use the same licence key for latest version or what version can we install is this key???

    We have several licences of Adobe Photoshop Elements V9 can we use the same licence key for latest version or what version can we install is this key???
    We are Gouvernment and we use Windows 7 64 bits edition with office 2010.
    Thanks.

    Hi Denis, if you have license of Photosho Elements V9 then you can only install V9, please check the download link: Download Photoshop Elements products | 9, 8, 7. Please also check System requirements | Adobe Photoshop Elements
    Atul_Saini

  • My hard drive & mother board had to be replaced, I am trying to setup my laptop & trying to re-sync but it will not let me use my old sync key, how do I reactivate using old sync key???

    I have my old sync key, but it keeps saying that it is the wrong one every time I try to setup the sync option...how do I clear out what is currently on there so I can use my old sync key and get my original info back?

    When you go to set up Sync - '''''I already have a Sync account''''', then in the next window use '''''I don't have the device with me'''''
    As you type the Sync Key, don't type the hypens between the alpha / numeric characters.

  • Use byte array of PDF to display PDF in IE browser

    I get byte array of PDF as input argument. I need to use byte array to display PDF in IE browser. I am writing code in doGet method of Servlet to accomplish this. However, PDF never gets displayed. I see Acrobat starting, but original PDF never gets displayed in browser.
    I am using code below in doGet of Servlet:
    resp.setContentType("application/pdf");
    resp.setHeader("Expires", "0");
    resp.setHeader("Cache-Control","must-revalidate, post-check=0,
    pre-check=0");
    resp.setHeader("Pragma", "public");
    resp.setHeader("Pragma", "no-cache"); //HTTP 1.0
    resp.setDateHeader("Expires", 0); //prevents caching at the proxy
    server
    resp.setHeader("Cache-Control", "no-cache"); //HTTP 1.1
    resp.setHeader("Cache-Control", "max-age=0");
    resp.setHeader("Content-disposition", "inline; filename=stuff.pdf");
    byte[] inBytes = getBytesOfPDF(...);
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    if(inBytes !=null){
    outStream.write(inBytes);
    outStream.flush();
    I added dummy name of PDF (stuff.pdf) for display, as I heard IE requires a file name with .pdf extension for display.
    But I had no luck with the code above.
    Any help with code will be appreciated.
    [email protected]

    Hi
    Am using the same code and i am able to get the PDF out.
              /* Finally writing it into a PDF */
                   response.setContentType("application/pdf");
                   /* filename could be any thing */
                   response.setHeader("Content-Disposition",
                             "attachment; filename=Report.pdf");
                   response.setContentLength(content.length);
                   response.getOutputStream().write(content);
                   response.getOutputStream().flush();
    But this also throws a error in the server :
    java.lang.IllegalStateException: getOutputStream() has already been called for this response
         at org.apache.catalina.connector.Response.getWriter(Response.java:606)
         at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:195)
         at org.springframework.web.servlet.view.freemarker.FreeMarkerView.processTemplate(FreeMarkerView.java:344)
         at org.springframework.web.servlet.view.freemarker.FreeMarkerView.doRender(FreeMarkerView.java:280)
         at org.springframework.web.servlet.view.freemarker.FreeMarkerView.renderMergedTemplateModel(FreeMarkerView.java:225)
         at org.springframework.web.servlet.view.AbstractTemplateView.renderMergedOutputModel(AbstractTemplateView.java:174)
         at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:239)
         at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1142)
         at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:879)
         at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:792)
         at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
         at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:441)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
         at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
         at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:463)
         at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:398)
         at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
         at org.ca.ielts.presentationtier.servlet.AuthorisationAuthenticationFilter.doFilter(Unknown Source)
         at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
         at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
         at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
         at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
         at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
         at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
         at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
         at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
         at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
         at java.lang.Thread.run(Thread.java:595)
    Any Clues how this has to be fixed.????

  • HT3887 how can i configure my wireless keyword so i can use the Function F keys to control volume etc...? I am using 10.5.8 OS

    how can i configure my wireless keyword so i can use the Function <F> keys to control volume etc...? I am using 10.5.8 OS

    little wireless cameras would not have the ability to send back to the base, even thought the base can reach it.
    Now if you take regular cameras and wire them into a Cisco switch that was attached to a wireless bridge that could shine back to the base...now you might have something, but your still going to have to do a survey/path analysis to determine if it is feasible.
    Coverage isnt throughput. I see one base station with 3 or 4 sectoral antennas depending on direction, pointing two several distribution bridges to bridge the gaps that go out again to the cameras...something like that. And all of it should be higher in the air than your construction.

  • How can I use the MS Windows Key in Linux

    Hello!
    I'm using KDE 4.3 and want to use the MS Windows Key to open the KDE start menu.
    I tried to add the Windows Key by pressing as a "KDE Application Launcher" hotkey, but the window key wasn't accepted as a hotkey.
    Is it possible to add this key as a hotkey?
    Thanks for help!
    Best regards,
    Flasher

    I have the following line in my .xinitrc:
    /usr/bin/xmodmap -e "keycode 133 = F30" &
    ...where keycode 133 is my win key. I assign it to F30 (it can be any number besides 1-12, I guess), and then it's just a matter of configuring escape key (in your case, it'll be kde start menu) to F30.

  • Reinstallation of adobe acrobat pro using the same license key on the same machine.

    How to reinstall Adobe Acrobat pro using the same license key on the same machine.

    Is it currently installed and working?
    Installed and broken?
    Or on a wiped machine, nothing there?

  • Menu Creation and Using the SELECT soft key

    Hi,
    I am trying to design a menu similar to the thumbnail menus available in most phone these days.what i want is a set of icons placed in a tabular format ie rows and colums. the joystick control can be used to navigate thru the icons and using the select soft key ie the middle button of the soft keys, the next set of forms can be displayed.
    so far, i have created a form, used a few image item and used the Item's layout directive to arrange the imageItem as i want on the display. I can get the joystick to navigate between the imageItems however the select button doesnt fire any event.
    I have added a command to each of the items and set an ItemCommandListener.
    That approach seems to be working fine but it defeats my purpose. the reason being i had problems with the mapping of the command keys. For each display i had an option of going to the main menu and to the next screen. On the emulator it maps perfectly with the left key having the main menu and the right key having the "next form" button. But while implementing on the phone, the left key has the main menu but the right key shows "more options", when u click more options you get the "next form" button. This is happening in every form on display and makes it more tideous to use.
    Thats why i was hoping to get the select button working if possible. Any help would be much appreciated.

    Try searching J2mepolish.org plenty of work is done
    with Regards
    Rizwan

  • Command C andV stop working just in Microsoft Word. what should i do?i can't use them as shortcut keys in word documents!

    Hi:
    I have a really annoying problem. command C andV stop working just in Microsoft Word. what should i do?i can't use them as shortcut keys in word documents! however they are working in other applications, the problem is just in word documents!

    I just had the same thing happen on my Macbook but was able to resolve it (at least for now!). Here's what I did:
    Go to Tools>Customize Keyboard
    You can then select 'edit' on the left side under categories. Then on the right side, you'll see lots of commands. Scroll down till you find the ones that aren't working. Ex. Editcopy, Editpaste.
    Select each one and check to see if there is a command short cut. Ex. for editcopy it should read: "Command C"
    If it does not (i.e. the problem), put the cursor in "Press new keyboard shortcut." Then press the command key along with the corresponding letter. Note you will not type the letters out but actually do the command. Then press "Assign." The shortcut command should then appear under 'Current Keys.' Go through and check all of the ones that aren't working for you.
    BTW, this is a nifty was to add some cool commands that you use often. Ex. insert row on table, etc.
    Quit Word and restart it. It should work. Hope that helps!

  • Should I save memory by using byte, short and float?

    Our teacher tells us always to use int and double. But what if I don't need such precision or large values?
    Shouldn't I use byte, short and float instead?

    You don't save any memory if you use floats instead of doubles in a method. These variables only exist on the stack when the method is executing. Also remember that Java may do type conversions from float to double in expressions. This may make your code slower.
    If you have a class with large quantities of doubles, for example an array of 100000 doubles, then you may consider using floats, because the memory saving is substantial. If you access the array from outside the class via double methods you can easily do this change local to the class late in the development process.
    I'd say generally it's better to do as your teacher says and standardize on doubles and integers. If you write your program well you can always optimize later if you have to.

  • How can I uses byte[] to represent the length of a message?

    hihi,
    I want to using 3-bytes to represent the length of a message that send over a socket,
    I don't know how to using byte to represent the length, should I parse integer to byte?
    thank you

    int length;
    DataOutputStream dos = ...;
    dos.writeByte(length >>> 16);
    dos.writeByte(length >>> 8);
    dos.writeByte(length & 0xff);But why 3? Why not 2 or 4 like everybody else? with DataOutputStream.writeShort() or writeInt()?

Maybe you are looking for