DenVdmj / js-crunchy

Automatically exported from code.google.com/p/js-crunchy
1 stars 0 forks source link

this code make cruncher dead #7

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.
Array.prototype.binarySearch=function(v,c){var
l=0,r=this.length-1,m;if(c!=null){var
i;while(l<=r){m=(l+r)>>1;i=c(this[m],v);if(i==0)return m;if(i<0)l=m+1;else
r=m-1;}}else{while(l<=r){m=(l+r)>>1;this[m]==v)return
m;if(this[m]<v)l=m+1;else r=m-1;}}return ~l};

on this code cruncher goes to sleep

Original issue reported on code.google.com by malakhov...@gmail.com on 6 Aug 2008 at 4:39

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I find what kill the crancher - this is symbol "~" (bitwise not)

Original comment by malakhov...@gmail.com on 6 Aug 2008 at 4:56

GoogleCodeExporter commented 9 years ago
The code in this project is an old version, as I closed the google account it 
belonged to, and forgot that this was on it, so I no longer have any control 
over 
it. There's a more up to date version at http://www.calamity.org.uk/crunchy/ 
which 
doesn't have this bug. I'll make the source available soon.

Incidentally, your code has an error in it, the line:

r=m-1;}}else{while(l<=r){m=(l+r)>>1;this[m]==v)return

has a an unmatched ')'. I think it should be:

r=m-1;}}else{while(l<=r){m=(l+r)>>1;if(this[m]==v)return

Original comment by dnl...@gmail.com on 7 Aug 2008 at 6:24

GoogleCodeExporter commented 9 years ago
hm... I my original code is

Array.prototype.binarySearch = function( value, comparer ) { var l = 0, r =
this.length-1, m; if( comparer != null ) { var res; while( l <= r ) { m = ( l + 
r )
>> 1; res = comparer( this[m], value ); if( res == 0 ) return m; if( res < 0 ) 
l = m
+ 1; else r = m - 1; } } else { while( l <= r ) { m = ( l + r ) >> 1; if( 
this[m] ==
value ) return m; if( this[m] < value ) l = m + 1; else r = m - 1; } } return 
~l; }

no error here, I think that cruncher make this, or maybe I make this error while
copy-pasting and playing with it... :)

I hope that sources will available soon... project is very interesting! 
so I have some ideas how to make more compression ratio, and I think that be 
cool to
make Javascript LINT based on your sources

Original comment by malakhov...@gmail.com on 8 Aug 2008 at 6:39