HighTechTalks DotNet Forums  

Bug in Collections.binarySearch

Dotnet VJSharp microsoft.public.dotnet.vjsharp


Discuss Bug in Collections.binarySearch in the Dotnet VJSharp forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Ingo Lundberg
 
Posts: n/a

Default Bug in Collections.binarySearch - 11-04-2004 , 09:32 AM






Hi all,

I think I've encountered a bug in the J# Java Collections.binarySearch.
Can some one confirm?

I've compiled and run the program below with both javac (j2sdk1.4.2_06) and
vjc (7.10.3077.0 under .Net 1.1.4322).

The pure Java pgm produces:
Search for 5 gave position 1
Search for 8 gave position 2
Search for 3 gave position 0
Search for 4 gave position -2
Search for -2 gave position -1
Search for 12 gave position -4

The J# pgm produces:
Search for 5 gave position 1
Search for 8 gave position 2
Search for 3 gave position 0
Search for 4 gave position -3
Search for -2 gave position -3
Search for 12 gave position -4

As a side mark I can tell you that the .Net ArrayList.BinarySearch produces
the same as the pure Java pgm. If nothing else, I take it as a sign that
Collections.binarySearch isn't based on the CLR implementation.

Regards,
Ingo




Reply With Quote
  #2  
Old   
Ingo Lundberg
 
Posts: n/a

Default Re: Bug in Collections.binarySearch - 11-04-2004 , 09:39 AM






Sorry about the missing source code (darn those differences in keyboard
shortcuts). Here it is. The custom comparator is mainly there so that I can
trace every comparision done.

import java.util.Date;
import java.util.ArrayList;
import java.util.Collections;

public class MyBS
{
public static void main(String[] args)
{
MyBS q = new MyBS();
q.DoIt();
}

public void DoIt()
{
ArrayList l = new ArrayList();
l.add(new Integer(3));
l.add(new Integer(5));
l.add(new Integer(8));

IComp cmp = new IComp();

int search = 5;
int p = java.util.Collections.binarySearch(l, new Integer(search),
cmp);
System.out.println("Search for " + search + " gave position " + p);

search = 8;
p = java.util.Collections.binarySearch(l, new Integer(search), cmp);
System.out.println("Search for " + search + " gave position " + p);

search = 3;
p = java.util.Collections.binarySearch(l, new Integer(search), cmp);
System.out.println("Search for " + search + " gave position " + p);

search = 4;
p = java.util.Collections.binarySearch(l, new Integer(search), cmp);
System.out.println("Search for " + search + " gave position " + p);

search = -2;
p = java.util.Collections.binarySearch(l, new Integer(search), cmp);
System.out.println("Search for " + search + " gave position " + p);

search = 12;
p = java.util.Collections.binarySearch(l, new Integer(search), cmp);
System.out.println("Search for " + search + " gave position " + p);
}

class IComp implements java.util.Comparator
{
public int compare(Object o1, Object o2)
{
Integer i1 = (Integer)o1;
Integer i2 = (Integer)o2;

int res = i1.compareTo(i2);
// System.out.println("IComp: " + res);
return res;
}
}
}


"Ingo Lundberg" <ingemar.lundberg (AT) __I_hate_spam__ (DOT) knowit.se> skrev i
meddelandet news:OPyEZsnwEHA.4004 (AT) tk2msftngp13 (DOT) phx.gbl...
Quote:
Hi all,

I think I've encountered a bug in the J# Java Collections.binarySearch.
Can some one confirm?

I've compiled and run the program below with both javac (j2sdk1.4.2_06)
and vjc (7.10.3077.0 under .Net 1.1.4322).

The pure Java pgm produces:
Search for 5 gave position 1
Search for 8 gave position 2
Search for 3 gave position 0
Search for 4 gave position -2
Search for -2 gave position -1
Search for 12 gave position -4

The J# pgm produces:
Search for 5 gave position 1
Search for 8 gave position 2
Search for 3 gave position 0
Search for 4 gave position -3
Search for -2 gave position -3
Search for 12 gave position -4

As a side mark I can tell you that the .Net ArrayList.BinarySearch
produces the same as the pure Java pgm. If nothing else, I take it as a
sign that Collections.binarySearch isn't based on the CLR implementation.

Regards,
Ingo






Reply With Quote
  #3  
Old   
AT
 
Posts: n/a

Default Re: Bug in Collections.binarySearch - 11-06-2004 , 01:52 AM



This bug has been fixed in the "The Microsoft Supplemental UI Library for
Visual J# .NET v1.1" release.
It provides much of the functionality described in the Java 2 JFC Swing
specification. It also adds support for much of the functionality found in
the JDK 1.2 java.util package. The Supplemental UI Library installs as an
add-on to Visual J# .NET 2003.

For more details and downloading this add-on please goto following link
http://msdn.microsoft.com/vjsharp/supui/

Thanks for reporting this issue.
Amit
--------------------
Quote:
From: "Ingo Lundberg" <ingemar.lundberg (AT) __I_hate_spam__ (DOT) knowit.se
References: <OPyEZsnwEHA.4004 (AT) tk2msftngp13 (DOT) phx.gbl
Subject: Re: Bug in Collections.binarySearch
Date: Thu, 4 Nov 2004 15:39:59 +0100
Lines: 103
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Response
Message-ID: <Ow5jpwnwEHA.4040 (AT) TK2MSFTNGP11 (DOT) phx.gbl
Newsgroups: microsoft.public.dotnet.vjsharp
NNTP-Posting-Host: v-424-adsl-12.bitnet.nu 82.196.96.12
Path:
cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl!TK2MSFT NGP08.phx.gbl!TK2MSFTNGP11
.phx.gbl
Quote:
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.vjsharp:6617
X-Tomcat-NG: microsoft.public.dotnet.vjsharp

Sorry about the missing source code (darn those differences in keyboard
shortcuts). Here it is. The custom comparator is mainly there so that I
can
trace every comparision done.

import java.util.Date;
import java.util.ArrayList;
import java.util.Collections;

public class MyBS
{
public static void main(String[] args)
{
MyBS q = new MyBS();
q.DoIt();
}

public void DoIt()
{
ArrayList l = new ArrayList();
l.add(new Integer(3));
l.add(new Integer(5));
l.add(new Integer(8));

IComp cmp = new IComp();

int search = 5;
int p = java.util.Collections.binarySearch(l, new Integer(search),
cmp);
System.out.println("Search for " + search + " gave position " + p);

search = 8;
p = java.util.Collections.binarySearch(l, new Integer(search),
cmp);
System.out.println("Search for " + search + " gave position " + p);

search = 3;
p = java.util.Collections.binarySearch(l, new Integer(search),
cmp);
System.out.println("Search for " + search + " gave position " + p);

search = 4;
p = java.util.Collections.binarySearch(l, new Integer(search),
cmp);
System.out.println("Search for " + search + " gave position " + p);

search = -2;
p = java.util.Collections.binarySearch(l, new Integer(search),
cmp);
System.out.println("Search for " + search + " gave position " + p);

search = 12;
p = java.util.Collections.binarySearch(l, new Integer(search),
cmp);
System.out.println("Search for " + search + " gave position " + p);
}

class IComp implements java.util.Comparator
{
public int compare(Object o1, Object o2)
{
Integer i1 = (Integer)o1;
Integer i2 = (Integer)o2;

int res = i1.compareTo(i2);
// System.out.println("IComp: " + res);
return res;
}
}
}


"Ingo Lundberg" <ingemar.lundberg (AT) __I_hate_spam__ (DOT) knowit.se> skrev i
meddelandet news:OPyEZsnwEHA.4004 (AT) tk2msftngp13 (DOT) phx.gbl...
Hi all,

I think I've encountered a bug in the J# Java Collections.binarySearch.
Can some one confirm?

I've compiled and run the program below with both javac (j2sdk1.4.2_06)
and vjc (7.10.3077.0 under .Net 1.1.4322).

The pure Java pgm produces:
Search for 5 gave position 1
Search for 8 gave position 2
Search for 3 gave position 0
Search for 4 gave position -2
Search for -2 gave position -1
Search for 12 gave position -4

The J# pgm produces:
Search for 5 gave position 1
Search for 8 gave position 2
Search for 3 gave position 0
Search for 4 gave position -3
Search for -2 gave position -3
Search for 12 gave position -4

As a side mark I can tell you that the .Net ArrayList.BinarySearch
produces the same as the pure Java pgm. If nothing else, I take it as a
sign that Collections.binarySearch isn't based on the CLR implementation.

Regards,
Ingo








Reply With Quote
  #4  
Old   
Ingo Lundberg
 
Posts: n/a

Default Re: Bug in Collections.binarySearch - 11-06-2004 , 05:19 AM



Thank you very much, I’m happy to confirm that the fix worked fine on my
test case.
Regards,
Ingo


"Amit Bhagwat [MSFT]" <Amit.vjc (AT) online (DOT) microsoft.com> skrev i meddelandet
news:QBsNA18wEHA.768 (AT) cpmsftngxa10 (DOT) phx.gbl...
Quote:
This bug has been fixed in the "The Microsoft Supplemental UI Library for
Visual J# .NET v1.1" release.
It provides much of the functionality described in the Java 2 JFC Swing
specification. It also adds support for much of the functionality found in
the JDK 1.2 java.util package. The Supplemental UI Library installs as an
add-on to Visual J# .NET 2003.

For more details and downloading this add-on please goto following link
http://msdn.microsoft.com/vjsharp/supui/

Thanks for reporting this issue.
Amit
--------------------
From: "Ingo Lundberg" <ingemar.lundberg (AT) __I_hate_spam__ (DOT) knowit.se
References: <OPyEZsnwEHA.4004 (AT) tk2msftngp13 (DOT) phx.gbl
Subject: Re: Bug in Collections.binarySearch
Date: Thu, 4 Nov 2004 15:39:59 +0100
Lines: 103
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
X-RFC2646: Format=Flowed; Response
Message-ID: <Ow5jpwnwEHA.4040 (AT) TK2MSFTNGP11 (DOT) phx.gbl
Newsgroups: microsoft.public.dotnet.vjsharp
NNTP-Posting-Host: v-424-adsl-12.bitnet.nu 82.196.96.12
Path:
cpmsftngxa10.phx.gbl!TK2MSFTNGXA03.phx.gbl!TK2MSFT NGP08.phx.gbl!TK2MSFTNGP11
phx.gbl
Xref: cpmsftngxa10.phx.gbl microsoft.public.dotnet.vjsharp:6617
X-Tomcat-NG: microsoft.public.dotnet.vjsharp

Sorry about the missing source code (darn those differences in keyboard
shortcuts). Here it is. The custom comparator is mainly there so that I
can
trace every comparision done.

import java.util.Date;
import java.util.ArrayList;
import java.util.Collections;

public class MyBS
{
public static void main(String[] args)
{
MyBS q = new MyBS();
q.DoIt();
}

public void DoIt()
{
ArrayList l = new ArrayList();
l.add(new Integer(3));
l.add(new Integer(5));
l.add(new Integer(8));

IComp cmp = new IComp();

int search = 5;
int p = java.util.Collections.binarySearch(l, new Integer(search),
cmp);
System.out.println("Search for " + search + " gave position " +
p);

search = 8;
p = java.util.Collections.binarySearch(l, new Integer(search),
cmp);
System.out.println("Search for " + search + " gave position " +
p);

search = 3;
p = java.util.Collections.binarySearch(l, new Integer(search),
cmp);
System.out.println("Search for " + search + " gave position " +
p);

search = 4;
p = java.util.Collections.binarySearch(l, new Integer(search),
cmp);
System.out.println("Search for " + search + " gave position " +
p);

search = -2;
p = java.util.Collections.binarySearch(l, new Integer(search),
cmp);
System.out.println("Search for " + search + " gave position " +
p);

search = 12;
p = java.util.Collections.binarySearch(l, new Integer(search),
cmp);
System.out.println("Search for " + search + " gave position " +
p);
}

class IComp implements java.util.Comparator
{
public int compare(Object o1, Object o2)
{
Integer i1 = (Integer)o1;
Integer i2 = (Integer)o2;

int res = i1.compareTo(i2);
// System.out.println("IComp: " + res);
return res;
}
}
}


"Ingo Lundberg" <ingemar.lundberg (AT) __I_hate_spam__ (DOT) knowit.se> skrev i
meddelandet news:OPyEZsnwEHA.4004 (AT) tk2msftngp13 (DOT) phx.gbl...
Hi all,

I think I've encountered a bug in the J# Java Collections.binarySearch.
Can some one confirm?

I've compiled and run the program below with both javac (j2sdk1.4.2_06)
and vjc (7.10.3077.0 under .Net 1.1.4322).

The pure Java pgm produces:
Search for 5 gave position 1
Search for 8 gave position 2
Search for 3 gave position 0
Search for 4 gave position -2
Search for -2 gave position -1
Search for 12 gave position -4

The J# pgm produces:
Search for 5 gave position 1
Search for 8 gave position 2
Search for 3 gave position 0
Search for 4 gave position -3
Search for -2 gave position -3
Search for 12 gave position -4

As a side mark I can tell you that the .Net ArrayList.BinarySearch
produces the same as the pure Java pgm. If nothing else, I take it as a
sign that Collections.binarySearch isn't based on the CLR
implementation.

Regards,
Ingo










Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.