long[] bitset = BitsUtil.zero(capacity); while(BitsUtil.cardinality(bitset) < cardinality) { BitsUtil.setI(bitset, random.nextInt(capacity)); long[] bitset = BitsUtil.ones(capacity); while(BitsUtil.cardinality(bitset) > cardinality) { BitsUtil.clearI(bitset, random.nextInt(capacity));
final int numdim = coords.length; final int numbits = numdim * bitsperdim; final long[] output = BitsUtil.zero(numbits); long[] refl = BitsUtil.zero(numdim); for (int i = 0; i < bitsperdim; i++) { final long[] hist = interleaveBits(coords, i + offset); final long[] bits = BitsUtil.copy(hist); BitsUtil.xorI(bits, refl); BitsUtil.cycleRightI(bits, rotation, numdim); final int nextrot = (rotation + BitsUtil.numberOfTrailingZerosSigned(bits) + 2) % numdim; BitsUtil.invgrayI(bits); BitsUtil.orI(output, bits, numbits - (i + 1) * numdim); BitsUtil.flipI(refl, rotation); if (!BitsUtil.get(bits, 0)) { BitsUtil.flipI(refl, (nextrot - 1 + numdim) % numdim);
@Override public DBIDIter advance() { pos = BitsUtil.nextSetBit(bits, pos + 1); return this; }
/** * The magnitude is the position of the highest bit set * * @param v Vector v * @return position of highest bit set, or 0. */ public static int magnitude(long[] v) { final int l = numberOfLeadingZeros(v); return capacity(v) - l; }
DenseItemset scratch = new DenseItemset(BitsUtil.zero(dim), length - 1); BitsUtil.xorI(scratch.items, ij.items); if(BitsUtil.cardinality(scratch.items) != 2) { break prefix; // No prefix match; since sorted, no more can follow! int first = BitsUtil.nextSetBit(scratch.items, 0); if(BitsUtil.nextSetBit(ii.items, first + 1) > -1) { break prefix; // Different overlap by chance? BitsUtil.orI(scratch.items, ij.items); for(int l = length, b = BitsUtil.nextSetBit(scratch.items, 0); l > 2; l--, b = BitsUtil.nextSetBit(scratch.items, b + 1)) { BitsUtil.clearI(scratch.items, b); int pos = Collections.binarySearch(supported, scratch); if(pos < 0) { continue prefix; BitsUtil.setI(scratch.items, b);
long[] nD = BitsUtil.zero(d); BitsUtil.setI(nD, k); if(D == null || BitsUtil.cardinality(nD) > BitsUtil.cardinality(D)) { D = nD; dV.set(iter); if(BitsUtil.cardinality(D) >= d_zero) { if(iprogress != null) { iprogress.setProcessed(iprogress.getTotal(), LOG); if(D == null || BitsUtil.cardinality(D) == 0) { return null;
public List<Polygon> compute() { // Compute delaunay triangulation: delaunay = (new SweepHullDelaunay2D(points)).getDelaunay(); List<Polygon> polys = new ArrayList<>(); // Working data long[] used = BitsUtil.zero(delaunay.size()); List<Vector> cur = new ArrayList<>(); for(int i = 0 /* = used.nextClearBit(0) */; i < delaunay.size() && i >= 0; i = BitsUtil.nextClearBit(used, i + 1)) { if(!BitsUtil.get(used, i)) { BitsUtil.setI(used, i); SweepHullDelaunay2D.Triangle tri = delaunay.get(i); if(tri.r2 <= alpha2) { // Check neighbors processNeighbor(cur, used, i, tri.ab, tri.b); processNeighbor(cur, used, i, tri.bc, tri.c); processNeighbor(cur, used, i, tri.ca, tri.a); } if(cur.size() > 0) { polys.add(new Polygon(cur)); cur = new ArrayList<>(); } } } return polys; }
@Override public <N extends AbstractRStarTreeNode<N, E>, E extends SpatialEntry> boolean handleOverflow(AbstractRStarTree<N, E, ?> tree, N node, IndexTreePath<E> path) { final int depthm1 = path.getPathCount() - 1; // No reinsertions at root level if(depthm1 == 0) { return false; } // Earlier reinsertions at the same level if(BitsUtil.capacity(reinsertions) < depthm1) { reinsertions = BitsUtil.copy(reinsertions, depthm1); } if(BitsUtil.get(reinsertions, depthm1)) { return false; } BitsUtil.setI(reinsertions, depthm1); final E entry = path.getEntry(); assert (!entry.isLeafEntry()) : "Unexpected leaf entry"; int[] cands = reinsertStrategy.computeReinserts(node, NodeArrayAdapter.STATIC, entry); if(cands == null || cands.length == 0) { return false; } tree.reInsert(node, path, cands); return true; }
/** * Returns true if this subspace is a subspace of the specified subspace, i.e. * if the set of dimensions building this subspace are contained in the set of * dimensions building the specified subspace. * * @param subspace the subspace to test * @return true if this subspace is a subspace of the specified subspace, * false otherwise */ public boolean isSubspace(Subspace subspace) { if(this.dimensionality > subspace.dimensionality) { return false; } // FIXME: use bit operations. for(int d = BitsUtil.nextSetBit(dimensions, 0); d >= 0; d = BitsUtil.nextSetBit(dimensions, d + 1)) { if(!BitsUtil.get(subspace.dimensions, d)) { return false; } } return true; }
/** * Get the resulting dimensionality. * * @return dimensionality */ public int getDimensionality() { return BitsUtil.cardinality(selectedAttributes); }
/** * Test if the current column is marked as label column. * * @param col Column number * @return {@code true} when a label column. */ protected boolean isLabelColumn(int col) { return labelIndices != null && BitsUtil.get(labelIndices, col); }
/** * Assigns the first object of the specified list to the first assignment that * it is not yet assigned to the second assignment. * * @param assign Output assignment * @param assigned Bitset of assigned objects * @param dis Distances * @param idx Indexes * @param pos Current position * @param second Assign to second, not first, set. * @return the new index */ private int assignBest(Assignments<E> assign, long[] assigned, N node, double[] dis, int[] idx, int pos, boolean second) { int i = idx[pos]; // Skip already assigned objects: while(BitsUtil.get(assigned, i)) { i = idx[++pos]; } if(second) { assign.addToSecond(node.getEntry(i), dis[pos], i); } else { assign.addToFirst(node.getEntry(i), dis[pos], i); } BitsUtil.setI(assigned, i); return ++pos; }
Pair<long[], ArrayModifiableDBIDs> noise = new Pair<>(BitsUtil.zero(dimensionality), DBIDUtil.newArray()); for(long[] pv : clustersMap.keySet()) { if(BitsUtil.cardinality(pv) == 0) { List<ArrayModifiableDBIDs> parallelClusters = clustersMap.get(pv); for(ArrayModifiableDBIDs c : parallelClusters) { List<ArrayModifiableDBIDs> newParallelClusters = new ArrayList<>(parallelClusters.size()); for(ArrayModifiableDBIDs c : parallelClusters) { if(!BitsUtil.isZero(pv) && c.size() < mu) { notAssigned.add(new Pair<>(pv, c));
@Override public <T extends SpatialComparable> void sort(List<T> objs, int start, int end, double[] minmax, int[] dims) { peanoSort(objs, start, end, minmax, dims, 0, BitsUtil.zero(minmax.length >> 1), false); }
/** * Returns the list of all {@code (d-1)}-dimensional subspaces of the * specified {@code d}-dimensional subspace. * * @param subspace the {@code d}-dimensional subspace * @return a list of all {@code (d-1)}-dimensional subspaces */ private List<Subspace> lowerSubspaces(Subspace subspace) { int dimensionality = subspace.dimensionality(); if(dimensionality <= 1) { return null; } // order result according to the dimensions List<Subspace> result = new ArrayList<>(); long[] dimensions = subspace.getDimensions(); for(int dim = BitsUtil.nextSetBit(dimensions, 0); dim >= 0; dim = BitsUtil.nextSetBit(dimensions, dim + 1)) { long[] newDimensions = dimensions.clone(); BitsUtil.clearI(newDimensions, dim); result.add(new Subspace(newDimensions)); } return result; }