package sa4la;

public class BinarySearch4Test {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		BinarySearch4Test t = new BinarySearch4Test();
		int result = t.search(100, 51);
		System.out.println("final result: " + result);
		
		System.out.println("------------------");
		result = t.tmpsearch(100, 51);
		System.out.println("final result: " + result);
		
	}

	// T郁\bh
	public int search(int offset, int size) {
		double partition = 0.7;// TCY̌
		int result = offset + size;

		System.out.println("Start Binary Search");

		while (size > 0) {
			int division = offset + (int) ((double) size * partition);
			System.out.println("["+offset+","+division+","+Integer.toString(offset+size-1)+"]");
			
			System.out.println("trying " + division + " rows");
//			System.out.println("Searching");

			// LÂŏꍇ
//			if (aneal.search(division)) {
			if (true) {
//				System.out.println("Get Locating Array with " + division + " rows.");
				size = division - offset;
				result = division;
			} else {
//				System.out.println("Failed to get Locating Array with " + division + " rows.");
				division++;
				size += offset - division;
				offset = division;
			}
		}
		return result;
	}

	// T郁\bh
	public int tmpsearch(int low, int range) {
		int high = low + range - 1;
		double partition = 0.7;// TCY̌
		int result = high + 1;
		
		System.out.println("Start Binary Search");

		while (low <= high) {
			int size = low + (int) ((double) (high - low) * partition);
			System.out.println("["+ low +","+ size +","+ high +"]");
			
			System.out.println("trying " + size + " rows");
//			System.out.println("Searching");

			// LÂŏꍇ
//			if (aneal.search(division)) {
			if (true) {
	//			System.out.println("Get Locating Array with " + size + " rows.");
				high = size;
				result = size;
				if (low == high)
					break;
			} else {
	//			System.out.println("Failed to get Locating Array with " + size + " rows.");
				low = size + 1;
			}
		}
		return result;
	}
}
