org.amino.alg.scan
Class ParallelScanner

java.lang.Object
  extended by org.amino.alg.scan.AbstractScanner
      extended by org.amino.alg.scan.ParallelScanner
All Implemented Interfaces:
Scanner

public class ParallelScanner
extends AbstractScanner

Implementation of parallel scanner.


Constructor Summary
ParallelScanner()
          Creates a new parallel scanner, with default number of threads that equals to the the number of logical processors.
ParallelScanner(int nthreads)
          Creates a new parallel scanner, with the specified number of threads "nthreads".
 
Method Summary
 int binarySearch(byte[] a, int from, int to, byte v)
          Search a byte value from byte-array.
 int[] findAll(byte[] a, byte[] v, int from, int to)
          Find the index of the any occurrence of the given sequence in an array segment.
 int[] findAll(byte[] a, byte v, int from, int to)
          Find the indices of all occurrences of the given value in an array segment.
 int findAny(byte[] a, byte[] v, int from, int to)
          Find the index of the any occurrence of the given sequence in an array segment.
 int findAny(byte[] a, byte v, int from, int to)
          Find the index of the any occurrence of the given value in an array segment.
 int findNext(byte[] a, byte[] v, int index)
          Find the next index of the given sequence in the array.
protected  int findNext(byte[] a, byte[] v, int from, int to)
          Find the next index of the given value in the array.
 int findNext(byte[] a, byte v, int index)
          Find the next index of the given value in the array.
protected  int findNext(byte[] a, byte v, int from, int to)
          Find the next index of the given value in the array.
 int findPrevious(byte[] a, byte[] v, int index)
          Find the previous index of the given value in the array.
protected  int findPrevious(byte[] a, byte[] v, int from, int to)
          Find the previous index of the given value in the array.
 int findPrevious(byte[] a, byte v, int index)
          Find the previous index of the given value in the array.
protected  int findPrevious(byte[] a, byte v, int from, int to)
          Find the previous index of the given value in the array.
 int replaceAll(byte[] a, byte[] v, byte[] r, int from, int to)
          Replace all occurrences of the search sequence with the replacement sequence.
 int replaceAll(byte[] a, byte v, byte r, int from, int to)
          Replace all occurrences of the search value with the replacement value.
 
Methods inherited from class org.amino.alg.scan.AbstractScanner
binarySearch, findAll, findAll, findAny, findAny, findFirst, findFirst, findLast, findLast, replaceAll, replaceAll
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ParallelScanner

public ParallelScanner(int nthreads)
Creates a new parallel scanner, with the specified number of threads "nthreads".

Parameters:
nthreads - number of threads to do parallel scan

ParallelScanner

public ParallelScanner()
Creates a new parallel scanner, with default number of threads that equals to the the number of logical processors.

Method Detail

findAll

public int[] findAll(byte[] a,
                     byte v,
                     int from,
                     int to)
Find the indices of all occurrences of the given value in an array segment.

Specified by:
findAll in interface Scanner
Parameters:
a - The array to search.
v - The value to search for.
from - starting index for search (inclusive)
to - ending index for search (exclusive)
Returns:
The array of indices of occurrences or null if none found.

findAll

public int[] findAll(byte[] a,
                     byte[] v,
                     int from,
                     int to)
Find the index of the any occurrence of the given sequence in an array segment.

Specified by:
findAll in interface Scanner
Parameters:
a - The array to search.
v - The sequence to search for.
from - starting index for search (inclusive)
to - ending index for search (exclusive)
Returns:
The array of indices of occurrences or null if none found.

findAny

public int findAny(byte[] a,
                   byte v,
                   int from,
                   int to)
Find the index of the any occurrence of the given value in an array segment.

Specified by:
findAny in interface Scanner
Parameters:
a - The array to search.
v - The value to search for.
from - starting index for search (inclusive)
to - ending index for search (exclusive)
Returns:
The index of the an occurrence or a negative value if not found.

findAny

public int findAny(byte[] a,
                   byte[] v,
                   int from,
                   int to)
Find the index of the any occurrence of the given sequence in an array segment.

Specified by:
findAny in interface Scanner
Parameters:
a - The array to search.
v - The sequence to search for.
from - starting index for search (inclusive)
to - ending index for search (exclusive)
Returns:
The index of the an occurrence or a negative value if not found.

findNext

public int findNext(byte[] a,
                    byte v,
                    int index)
Find the next index of the given value in the array.

Specified by:
findNext in interface Scanner
Parameters:
a - The array to search.
v - The value to search for.
index - The starting index for the search.
Returns:
The index of the occurrence or a negative value if not found.

findNext

public int findNext(byte[] a,
                    byte[] v,
                    int index)
Find the next index of the given sequence in the array.

Specified by:
findNext in interface Scanner
Parameters:
a - The array to search.
v - The sequence to search for.
index - The starting index for the search (inclusive).
Returns:
The index of the occurrence or a negative value if not found.

findPrevious

public int findPrevious(byte[] a,
                        byte v,
                        int index)
Find the previous index of the given value in the array.

Specified by:
findPrevious in interface Scanner
Parameters:
a - The array to search.
v - The value to search for.
index - The starting index for the search (exclusive, searching backward).
Returns:
The index of the occurrence or a negative value if not found.

findPrevious

public int findPrevious(byte[] a,
                        byte[] v,
                        int index)
Find the previous index of the given value in the array.

Specified by:
findPrevious in interface Scanner
Parameters:
a - The array to search.
v - The value to search for.
index - The starting index for the search (exclusive, searching backward).
Returns:
The index of the occurrence or a negative value if not found.

replaceAll

public int replaceAll(byte[] a,
                      byte v,
                      byte r,
                      int from,
                      int to)
Replace all occurrences of the search value with the replacement value.

Specified by:
replaceAll in interface Scanner
Parameters:
a - The array to search.
v - The sequence to search for.
r - The replacement sequence.
from - starting index for search (inclusive)
to - ending index for search (exclusive)
Returns:
The number of occurrences found and replaced.

replaceAll

public int replaceAll(byte[] a,
                      byte[] v,
                      byte[] r,
                      int from,
                      int to)
Replace all occurrences of the search sequence with the replacement sequence.

Specified by:
replaceAll in interface Scanner
Parameters:
a - The array to search.
v - The sequence to search for.
r - The replacement sequence.
from - starting index for search (inclusive)
to - ending index for search (exclusive)
Returns:
The number of occurrences found and replaced.

binarySearch

public int binarySearch(byte[] a,
                        int from,
                        int to,
                        byte v)
Search a byte value from byte-array.

Parameters:
a - The array to search.
from - starting index for search (inclusive)
to - ending index for search (exclusive)
v - The value to search for
Returns:
index of the search value if it succeeds; otherwise, (-(insertion point) - 1).

findNext

protected int findNext(byte[] a,
                       byte v,
                       int from,
                       int to)
Find the next index of the given value in the array.

Parameters:
a - The array to search.
v - The value to search for.
from - The starting index for the search.
to - The ending index for the search.
Returns:
The index of the occurrence or a negative value if not found.

findNext

protected int findNext(byte[] a,
                       byte[] v,
                       int from,
                       int to)
Find the next index of the given value in the array.

Parameters:
a - The array to search.
v - The value to search for.
from - The starting index for the search.
to - The ending index for the search.
Returns:
The index of the occurrence or a negative value if not found.

findPrevious

protected int findPrevious(byte[] a,
                           byte v,
                           int from,
                           int to)
Find the previous index of the given value in the array.

Parameters:
a - The array to search.
v - The value to search for.
from - The starting index for the search (exclusive, searching backward).
to - The ending index for the search (exclusive, searching backward).
Returns:
The index of the occurrence or a negative value if not found.

findPrevious

protected int findPrevious(byte[] a,
                           byte[] v,
                           int from,
                           int to)
Find the previous index of the given value in the array.

Parameters:
a - The array to search.
v - The value to search for.
from - The starting index for the search (exclusive, searching backward).
to - The ending index for the search (exclusive, searching backward).
Returns:
The index of the occurrence or a negative value if not found.


Copyright © 2008. All Rights Reserved.