Java Unsigned Number Create unsignedLocalIntersect2by2(final short[] set1, final int length1, final short[] set2, final int length2, final short[] buffer)

Here you can find the source of unsignedLocalIntersect2by2(final short[] set1, final int length1, final short[] set2, final int length2, final short[] buffer)

Description

unsigned Local Intersectby

License

Apache License

Declaration

protected static int unsignedLocalIntersect2by2(final short[] set1, final int length1, final short[] set2,
            final int length2, final short[] buffer) 

Method Source Code

//package com.java2s;
/*/*from w  ww .j av a 2 s. com*/
 * (c) the authors Licensed under the Apache License, Version 2.0.
 */

public class Main {
    protected static int unsignedLocalIntersect2by2(final short[] set1, final int length1, final short[] set2,
            final int length2, final short[] buffer) {
        if ((0 == length1) || (0 == length2)) {
            return 0;
        }
        int k1 = 0;
        int k2 = 0;
        int pos = 0;
        short s1 = set1[k1];
        short s2 = set2[k2];

        mainwhile: while (true) {
            int v1 = toIntUnsigned(s1);
            int v2 = toIntUnsigned(s2);
            if (v2 < v1) {
                do {
                    ++k2;
                    if (k2 == length2) {
                        break mainwhile;
                    }
                    s2 = set2[k2];
                    v2 = toIntUnsigned(s2);
                } while (v2 < v1);
            }
            if (v1 < v2) {
                do {
                    ++k1;
                    if (k1 == length1) {
                        break mainwhile;
                    }
                    s1 = set1[k1];
                    v1 = toIntUnsigned(s1);
                } while (v1 < v2);
            } else {
                // (set2[k2] == set1[k1])
                buffer[pos++] = s1;
                ++k1;
                if (k1 == length1) {
                    break;
                }
                ++k2;
                if (k2 == length2) {
                    break;
                }
                s1 = set1[k1];
                s2 = set2[k2];
            }
        }
        return pos;
    }

    protected static int toIntUnsigned(short x) {
        return x & 0xFFFF;
    }
}

Related

  1. unsignedIntToString(int x)
  2. unsignedIntToString(int x, int radix)
  3. unsignedIntValue(byte[] data, int offset)
  4. unsignedLeb128Size(int value)
  5. unsignedLessThan(long a, long b)
  6. unsignedLocalIntersect2by2Cardinality(final short[] set1, final int length1, final short[] set2, final int length2)
  7. unsignedLong(byte b)
  8. unsignedLongToByteArray(final long value)
  9. unsignedLongToString(long value)