Posted by Eonwe on Sat 18 Apr 07:59
report abuse | download | new post
- public class ShiftTest {
- private final static int MIN_VAL = 0;
- private final static int SHIFT = 5;
- private final static int DIVISOR = 1 << SHIFT;
- public static long testShift(int maxInt) {
- long sum = 0;
- for (int i = MIN_VAL; i < maxInt; i++) {
- sum += i >> SHIFT;
- }
- return sum;
- }
- public static long testDivide(int maxInt) {
- long sum = 0;
- for (int i = MIN_VAL; i < maxInt; i++) {
- sum += i / DIVISOR;
- }
- return sum;
- }
- public static Pair<Long, Long> testDividing(int maxInt, int shift) {
- long val1 = testShift(maxInt);
- long val2 = testDivide(maxInt);
- if (val1 != val2) {
- }
- return Pair.of(time1, time2);
- }
- final int divisor = 1 << 1;
- Pair<Long, Long> result = testDividing(maxInt, divisor);
- }
- /**
- * Small typed utility class for pairs.
- * Has public field for the values of pair and
- * those values cannot be null.
- *
- * @param <T>
- * @param <Y>
- */
- public final T first;
- public final Y second;
- /**
- *
- * @param first non-null
- * @param second non-null
- */
- public Pair(T first, Y second){
- if (first == null || second == null){
- }
- this.first = first;
- this.second = second;
- }
- public Pair(Pair<T,Y> source){
- first = source.first;
- second = source.second;
- }
- public Pair<T,Y> clone(){
- try{
- @SuppressWarnings("unchecked")
- Pair<T,Y> cloned = (Pair<T, Y>) super.clone();
- return cloned;
- getClass().getCanonicalName()+
- "does not support clone "+
- "even though it should");
- }
- }
- public static <T,Y> Pair<T,Y> of(T first, Y second){
- return new Pair<T,Y>(first, second);
- }
- public int hashCode(){
- return first.hashCode() ^ second.hashCode();
- }
- return "{"+first.toString()+", "+second.toString()+"}";
- }
- if (o instanceof Pair)
- {
- Pair<?,?> other = (Pair<?, ?>) o;
- return first.equals(other.first) && second.equals(other.second);
- }
- return false;
- }
- }
- }
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.