xbn.array
Class BinarySearchData

java.lang.Object
  |
  +--xbn.XBNObject
        |
        +--xbn.array.BinarySearchData

public class BinarySearchData
extends XBNObject

Data necessary to do a binary search with.

Source code:  BinarySearchData.java.  Example code:  XmplBinarySearchData_asc.java, XmplBinarySearchData_desc.java.  Unit tests:  xbn_junit.array.JUTUtilArray.java.

Specifically, referring to the array-being-searched: The minimum, middle and maximum bounds, and sort-order direction. See UtilArray.getMiddleIdx.

This object only works when you are searching an array that is ordered. Unique-ness is not required, but is more efficient.


Fields inherited from class xbn.XBNObject
bFALSE_IN_PRODUCTION, bTRUE_IN_PRODUCTION, sCNSTR, sES, sLINE_SEP
 
Constructor Summary
BinarySearchData(int i_arrayLength, boolean b_arrayOrderDirAscDesc)
          Create a BinarySearchData.
 
Method Summary
 int getIdxLeft()
          Get the left-most index that has not yet been searched.
 int getIdxMiddle()
          Get the next array index to analyze.
 int getIdxRight()
          Get the right-most index that has not yet been searched.
 int getLength()
          How long is the array that is being searched?
 boolean getOrderDirAscDesc()
          Is the array-being-searched ordered ascending or descending?
 void prepareForNextSearch(boolean b_siLessOrGreaterThanAE)
          Set the indexes for the next search.
 void reset()
          Reset the internally-held data, to search the array again.
 String toString()
          Get some information about this BinarySearchData.
 
Methods inherited from class xbn.XBNObject
getXMsgPrefix, sop, sopl, sopl, throwAX, throwAXIfBadStr, throwAXIfNull, throwAXSpoof
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BinarySearchData

public BinarySearchData(int i_arrayLength,
                        boolean b_arrayOrderDirAscDesc)

Create a BinarySearchData.

Parameters:
i_arrayLength - The length of the array to be searched. May not be less than one.
b_arrayOrderDirAscDesc - What direction is the array-to-be-searched ordered? If true, then ascending. If false, descending.
Method Detail

getIdxLeft

public final int getIdxLeft()

Get the left-most index that has not yet been searched.

When this object is originally created, or reset, this is set to 0.


getIdxMiddle

public final int getIdxMiddle()

Get the next array index to analyze.

When this object is originally created, or reset, this is set to [UtilArray].getMiddleIdx(getMiddleIdx(getIdxLeft(), getIdxRight())).


getIdxRight

public final int getIdxRight()

Get the right-most index that has not yet been searched.

When this object is originally created, or reset, this is set to (getLength() - 1).


getLength

public final int getLength()

How long is the array that is being searched?

Returns:
i_arrayLength Exactly as provided to the constructor.

reset

public final void reset()

Reset the internally-held data, to search the array again. This initializes this object to a state equal to that when it was originally created.

The left index is set to 0.
The middle index is set to [UtilArray].getMiddleIdx(getMiddleIdx(getIdxLeft(), getIdxRight())).
The right index is set to (getLength() - 1).


getOrderDirAscDesc

public final boolean getOrderDirAscDesc()

Is the array-being-searched ordered ascending or descending?

Returns:
b_arrayOrderDirAscDesc Exactly as provided to the constructor.

prepareForNextSearch

public final void prepareForNextSearch(boolean b_siLessOrGreaterThanAE)

Set the indexes for the next search. Do not call this function when the search item was found to be equal to an element of the array (there's no need for a "next search"!).

Parameters:
b_siLessOrGreaterThanAE - Was the search item less or greater than the array element just compared against? If true, the search item was found to be less than the array element. If false, the search item was found to be greater than the array element.

toString

public final String toString()

Get some information about this BinarySearchData.

Overrides:
toString in class Object



Copyright 1997-2003, Jeff Epstein, All Rights Reserved. See top of source code files for copyright notice.

 

http://sourceforge.net/projects/xbnjava

 

SourceForge.net Logo