Here you can find the source of xorI(long[] v, long[] o)
Parameter | Description |
---|---|
v | Primary object |
o | data to xor |
public static long[] xorI(long[] v, long[] o)
//package com.java2s; /*/* w ww . j a v a 2s . co m*/ This file is part of ELKI: Environment for Developing KDD-Applications Supported by Index-Structures Copyright (C) 2015 Ludwig-Maximilians-Universit?t M?nchen Lehr- und Forschungseinheit f?r Datenbanksysteme ELKI Development Team This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Shift factor for a long: 2^6 == 64 == Long.SIZE */ private static final int LONG_LOG2_SIZE = 6; /** Masking for long shifts. */ private static final int LONG_LOG2_MASK = 0x3f; /** * XOR o onto v inplace, i.e. v ^= o * * @param v Primary object * @param o data to xor * @return v */ public static long[] xorI(long[] v, long[] o) { assert (o.length <= v.length) : "Bit set sizes do not agree."; for (int i = 0; i < o.length; i++) { v[i] ^= o[i]; } return v; } /** * XOR o onto v inplace, i.e. v ^= (o << off) * * @param v Primary object * @param o data to or * @param off Offset * @return v */ public static long[] xorI(long[] v, long[] o, int off) { if (off == 0) { return xorI(v, o); } if (off < 0) { throw new UnsupportedOperationException("Negative shifts are not supported."); } // Break shift into integers to shift and bits to shift final int shiftWords = off >>> LONG_LOG2_SIZE; final int shiftBits = off & LONG_LOG2_MASK; if (shiftWords >= v.length) { return v; } // Simple case - multiple of word size if (shiftBits == 0) { final int end = Math.min(v.length, o.length + shiftWords); for (int i = shiftWords; i < end; i++) { v[i] ^= o[i - shiftWords]; } return v; } // Overlapping case final int unshiftBits = Long.SIZE - shiftBits; final int end = Math.min(v.length, o.length + shiftWords) - 1; for (int i = end; i > shiftWords; i--) { final int src = i - shiftWords; v[i] ^= (o[src] << shiftBits) | (o[src - 1] >>> unshiftBits); } v[shiftWords] ^= o[0] << shiftBits; return v; } }