Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 520643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:10:00+00:00 2026-05-13T08:10:00+00:00

I am trying to convert the following java binary search routine to as3. I

  • 0

I am trying to convert the following java binary search routine to as3.
I assume that ‘compareTo’ is a built in java method and that ‘>>>’ s a type of bitwise operation.

Can anyone familiar with both actionscript 3 and Java help with this?

package binary;

public class Finder {

  public static int find( String[ ] keys, String target) {
    int high = keys.length;
    int low = -1;
    while (high - low>1) {
      int probe = (low + high)>>> 1;
      if (keys[probe].compareTo(target) > 0)
        high = probe;
      else
        low = probe;
    }

    if (low==-1 || keys[low].compareTo(target) !=0)
      return -1;
    else
      return low;
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:10:01+00:00Added an answer on May 13, 2026 at 8:10 am

    You should use the built-in Flash features as much as possible. It makes your code easier to maintain and the resulting SWF will be faster and smaller. Check out the indexOf() method on Array.

    Is this homework or do you have some other reason for using a hand-written search?

    Edit: I should add that the built-in search is a linear search starting with the index you provide. If you have a large and already sorted array, the binary search may be faster. You’ll have to experiment where the cross-over is–it could be as low as 10. If your array is not already sorted, the built-in linear search will beat the pants off the combined sort and binary search.

    Second Edit: I was curious how large the array had to be for indexOf() to become slower so I ran a few tests. Searching an array of 50 items, indexOf() is faster for all items. Searching an array of 100,000 items, indexOf() is faster up to about 100, then the binary search dominates.

    To find the 50,000th item out of 100,000 items, binary search takes 0.0078ms while indexOf() takes 3.382ms.

    Here’s the test code. I’ve never performance tested AS3 before, so watching elapsed time on a quiescent machine is the best I’ve got. (sprintf is the implementation posted on SO. It is just used to generate strings.)

        private static var myArray:Array;
    
        public static function setup():void {
            myArray = new Array();
            for (var i:int=0; i < 50; ++i) {
                myArray[i] = sprintf("s%06d", i);
            }
        }
    
        public static function timingTest():void {
            if (myArray == null) {
                setup();
            }
    
            var start:Number = getTimer();
            for (var j:int=0; j < 5000; ++j) {
                if (binarySearch(myArray, "s000049") != 49) {
                    trace("oops!");
                }
            }
            trace("avg msecs per binarySearch " + (getTimer() - start)/j);
    
            start = getTimer();
            for (var k:int=0; k < 5000; ++k) {
                if (myArray.indexOf("s000049") != 49) {
                    trace("oops!");
                }
            }
            trace("avg msecs per indexOf " + (getTimer() - start)/k);
        }
    
        public static function binarySearch(keys:Array, target:String):int {
            var high:int = keys.length;
            var low:int = -1;
            while (high - low > 1) {
                var probe:int = (low + high) / 2;
                if (keys[probe] > target)
                    high = probe;
                else
                    low = probe;
            }
            if (low == -1 || keys[low] !== target)
                return -1;
            else
                return low;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 318k
  • Answers 318k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If the second, take a look at http://m.kozlenko.info/#Android which lists… May 13, 2026 at 11:51 pm
  • Editorial Team
    Editorial Team added an answer select minid from (select min(id) as min_id, max(id) as max_id,… May 13, 2026 at 11:51 pm
  • Editorial Team
    Editorial Team added an answer Regarding on the GridView control's RowUpdating event problem, it is… May 13, 2026 at 11:51 pm

Related Questions

I'm trying to pass parameters from a PHP middle tier to a java backend
I have the following class defined in my mapping XML file: <class name=com.data.StateRefData table=STATE_REF>
I'm going to develop a Firefox extension which uses some Java classes. The extension
I am trying to convert the following Perl regex I found in the Video::Filename
I am trying to convert the following code from msvc to gcc #define ltolower(ch)

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.