drasys.or.alg
Class SequentialSearch

java.lang.Object
  |
  +--drasys.or.alg.SequentialSearch

public class SequentialSearch
extends java.lang.Object
implements SearchI, java.io.Serializable

An implementation of a sequential search. Uses 'Object.equals()' for the default comparison. The compare object will be used for comparison if it is set.

References:

Introduction to Algorithms
    Thomas H. Cormen, et al / Hardcover / Published 1990

See Also:
Serialized Form

Constructor Summary
SequentialSearch()
          Uses 'Object.equals()' for the default comparison.
SequentialSearch(CompareI compare)
          Uses 'compare' for the comparison.
 
Method Summary
 int find(byte[] array, byte key)
          Returns the index of the first matching element.
 int find(byte[] array, byte key, int from, int to)
          Returns the index of the first matching element in the block.
 int find(double[] array, double key)
          Returns the index of the first matching element.
 int find(double[] array, double key, int from, int to)
          Returns the index of the first matching element in the block.
 int find(float[] array, float key)
          Returns the index of the first matching element.
 int find(float[] array, float key, int from, int to)
          Returns the index of the first matching element in the block.
 int find(int[] array, int key)
          Returns the index of the first matching element.
 int find(int[] array, int key, int from, int to)
          Returns the index of the first matching element in the block.
 int find(long[] array, long key)
          Returns the index of the first matching element.
 int find(long[] array, long key, int from, int to)
          Returns the index of the first matching element in the block.
 int find(java.lang.Object[] array, java.lang.Object key)
          Returns the index of the first matching element.
 int find(java.lang.Object[] array, java.lang.Object key, int from, int to)
          Returns the index of the first matching element in the block.
 int find(short[] array, short key)
          Returns the index of the first matching element.
 int find(short[] array, short key, int from, int to)
          Returns the index of the first matching element in the block.
 int find(java.lang.String[] array, java.lang.String key)
          Returns the index of the first matching element.
 int find(java.lang.String[] array, java.lang.String key, int from, int to)
          Returns the index of the first matching element in the block.
 int find(VectorI vector, double key)
          Returns the index of the first matching element.
 int find(VectorI vector, double key, int from, int to)
          Returns the index of the first matching element in the block.
 int find(java.util.Vector vector, java.lang.Object key)
          Returns the index of the first matching element.
 int find(java.util.Vector vector, java.lang.Object key, int from, int to)
          Returns the index of the first matching element in the block.
 CompareI getCompare()
          Gets the comparison object.
 int insertionIndex()
          If a find fails, this returns the index where the new element should be inserted.
 void setCompare(CompareI compare)
          Sets the comparison object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SequentialSearch

public SequentialSearch()
Uses 'Object.equals()' for the default comparison.

SequentialSearch

public SequentialSearch(CompareI compare)
Uses 'compare' for the comparison.
Method Detail

setCompare

public void setCompare(CompareI compare)
Sets the comparison object.
Specified by:
setCompare in interface SearchI

getCompare

public CompareI getCompare()
Gets the comparison object.
Specified by:
getCompare in interface SearchI

insertionIndex

public int insertionIndex()
If a find fails, this returns the index where the new element should be inserted.
Specified by:
insertionIndex in interface SearchI

find

public int find(java.lang.Object[] array,
                java.lang.Object key)
Returns the index of the first matching element.
Specified by:
find in interface SearchI
Returns:
-1 if the element is not found.

find

public int find(java.lang.Object[] array,
                java.lang.Object key,
                int from,
                int to)
Returns the index of the first matching element in the block. If the element is not found then the insert index is set to 'to+1'.
Specified by:
find in interface SearchI
Returns:
-1 if the element is not found.

find

public int find(java.util.Vector vector,
                java.lang.Object key)
Returns the index of the first matching element.
Specified by:
find in interface SearchI
Returns:
-1 if the element is not found.

find

public int find(java.util.Vector vector,
                java.lang.Object key,
                int from,
                int to)
Returns the index of the first matching element in the block. If the element is not found then the insert index is set to 'to+1'.
Specified by:
find in interface SearchI
Returns:
-1 if the element is not found.

find

public int find(int[] array,
                int key)
Returns the index of the first matching element.
Specified by:
find in interface SearchI
Returns:
-1 if the element is not found.

find

public int find(int[] array,
                int key,
                int from,
                int to)
Returns the index of the first matching element in the block. If the element is not found then the insert index is set to 'to+1'.
Specified by:
find in interface SearchI
Returns:
-1 if the element is not found.

find

public int find(short[] array,
                short key)
Returns the index of the first matching element.
Specified by:
find in interface SearchI
Returns:
-1 if the element is not found.

find

public int find(short[] array,
                short key,
                int from,
                int to)
Returns the index of the first matching element in the block. If the element is not found then the insert index is set to 'to+1'.
Specified by:
find in interface SearchI
Returns:
-1 if the element is not found.

find

public int find(byte[] array,
                byte key)
Returns the index of the first matching element.
Specified by:
find in interface SearchI
Returns:
-1 if the element is not found.

find

public int find(byte[] array,
                byte key,
                int from,
                int to)
Returns the index of the first matching element in the block. If the element is not found then the insert index is set to 'to+1'.
Specified by:
find in interface SearchI
Returns:
-1 if the element is not found.

find

public int find(double[] array,
                double key)
Returns the index of the first matching element.
Specified by:
find in interface SearchI
Returns:
-1 if the element is not found.

find

public int find(double[] array,
                double key,
                int from,
                int to)
Returns the index of the first matching element in the block. If the element is not found then the insert index is set to 'to+1'.
Specified by:
find in interface SearchI
Returns:
-1 if the element is not found.

find

public int find(float[] array,
                float key)
Returns the index of the first matching element.
Specified by:
find in interface SearchI
Returns:
-1 if the element is not found.

find

public int find(float[] array,
                float key,
                int from,
                int to)
Returns the index of the first matching element in the block. If the element is not found then the insert index is set to 'to+1'.
Specified by:
find in interface SearchI
Returns:
-1 if the element is not found.

find

public int find(long[] array,
                long key)
Returns the index of the first matching element.
Specified by:
find in interface SearchI
Returns:
-1 if the element is not found.

find

public int find(long[] array,
                long key,
                int from,
                int to)
Returns the index of the first matching element in the block. If the element is not found then the insert index is set to 'to+1'.
Specified by:
find in interface SearchI
Returns:
-1 if the element is not found.

find

public int find(java.lang.String[] array,
                java.lang.String key)
Returns the index of the first matching element.
Specified by:
find in interface SearchI
Returns:
-1 if the element is not found.

find

public int find(java.lang.String[] array,
                java.lang.String key,
                int from,
                int to)
Returns the index of the first matching element in the block. If the element is not found then the insert index is set to 'to+1'.
Specified by:
find in interface SearchI
Returns:
-1 if the element is not found.

find

public int find(VectorI vector,
                double key)
Returns the index of the first matching element.
Specified by:
find in interface SearchI
Returns:
-1 if the element is not found.

find

public int find(VectorI vector,
                double key,
                int from,
                int to)
Returns the index of the first matching element in the block. If the element is not found then the insert index is set to 'to+1'.
Specified by:
find in interface SearchI
Returns:
-1 if the element is not found.


Copyright(C)1997-2000 by DRA Systems all rights reserved. OpsResearch.com