I have a HTML list of about 500 items and a "filter" box above it. I started by using jQuery to filter the list when I typed a letter (timing code added later): $('#filter').keyup( function() { var jqStart = (new Date).getTime(); var search = $(this).val().toLowerCase(); var $list = $('ul.ablist > li'); $list.each( function() { if ( $(this).text().toLowerCase().indexOf(search) === -1 ) $(this).hide(); else $(this).show(); } ); console.log('Time: ' + ((new Date).getTime() - jqStart)); } ); However, there was a couple of seconds delay after typing each letter (particularly the first letter). So I thought it may be slightly quicker if I used plain Javascript (I read recently that jQuery's each function is particularly slow). Here's my JS equivalent: document.getElementById('filter').addEventListener( 'keyup', function () { var jsStart = (new Date).getTime()...
Vipan Singla's page on Bitwise Operations is quite nice.
ReplyDeleteIt is not language specific, but luckily, these operations work the same on Java as many languages (in particular, nearly all C-style languages work this way with bitwise operations). It is very visual, and uses tables to illustrate what happens by operation.
Additionally to the good introductory guide that Reed Copsey recommended I'd recommend a intresting collection of small real world samples that show what you can actually do with bit operators and that you might enjoy reading and experimenting with once you have got some basic understanding of how bitwise operators work.
ReplyDeleteRegarding the differences of bitwise operators between Java and C/C++: In Java you don't have unsigned numeric types (except char) but instead you have two right shift operators (>> and >>>) that allow you to do either a signed (>>) or a unsigned shift (>>>). A signed right shift copies the sign bit to all empty places on the left side while a unsigned right shift fills them with zero bits. Also, as booleans in Java cannot be be cast to ints, you cannot use boolean expressions directly as operands for bit operators. I.e. something like this works in C but not in Java:
val |= ( a > b );
In Java you would have to write this insead to do the same thing:
val |= ( a > b ) ? 1 : 0;
What's wrong with the WIkipedia article?
ReplyDeleteA perennial favorite: Sean Eron Anderson's Bit Twiddling Hacks.
ReplyDeleteAs an introduction to bitwise operations to represent sets and efficiently compute subsets I liked this tutorial. It contains links to samples, including Java code (if you keep following the links at the bottom of the linked pages).
ReplyDeleteAlso check Hacker's Delight, there is a sample chapter which is available online. Though not specific to Java, the programming tricks explained here would be applicable with Java also.
ReplyDelete