@Override public void union(Vector vector, VectorVectorMapper callback) { if (vector instanceof DenseVector || vector instanceof SparseVector) { vector.union(this, new VectorVectorReverseOrderMapper(callback)); } OffHeapVector v = (OffHeapVector) vector; int p1 = 0; int p2 = 0; for (; p1 < fillLevel && p2 < v.fillLevel; ) { if (index(p1) == v.index(p2)) { if (!callback.map(index(p1), value(p1), v.value(p2))) { return; } p1++; p2++; } else if (index(p1) < v.index(p2)) { if (!callback.map(index(p1), value(p1), 0)) { return; } p1++; } else { if (!callback.map(v.index(p2), 0, v.value(p2))) { return; } p2++; } } for (; p1 < fillLevel; p1++) { callback.map(index(p1), value(p1), 0); } for (; p2 < v.fillLevel; p2++) { callback.map(v.index(p2), 0, v.value(p2)); } }
@Override public void intersect(Vector vector, VectorVectorMapper callback) { if (vector instanceof DenseVector) { vector.intersect(this, new VectorVectorReverseOrderMapper(callback)); return; } if (vector instanceof SparseVector) { for (int i = 0; i < fillLevel; i++) { int ip1 = index(i); float v2 = vector.get(ip1); if (!NumberUtils.isZero(v2)) { float v1 = value(i); if (!NumberUtils.isZero(v1)) { if (!callback.map(ip1, value(i), v2)) { return; } } } } return; } OffHeapVector v = (OffHeapVector) vector; int p1 = 0; int p2 = 0; for (; p1 < fillLevel && p2 < v.fillLevel; ) { int ip1 = index(p1); int ip2 = v.index(p2); if (ip1 == ip2) { float v1 = value(p1); float v2 = v.value(p2); if (!NumberUtils.isZero(v1) && !NumberUtils.isZero(v2)) { if (!callback.map(ip1, v1, v2)) { return; } } p1++; p2++; } else if (ip1 < ip2) { p1++; } else { p2++; } } }