CompactHilbertCurve implements SpaceFillingCurve { @Override public void accept(ZoomingNavigator visitor) { BitVector[] p = new BitVector[n]; assert n == p.length; for (int i = 0; i < n; ++i) { p[i] = BitVectorFactories.OPTIMAL.apply(m[i]); } BitVector index = BitVectorFactories.OPTIMAL.apply(spec.sumBitsPerDimension()); e.clear(); int d = 0; int k = spec.sumBitsPerDimension(); t.clear(); w.clear(); BitVector[] wAndT = new BitVector[] {w, t}; final int mMax = spec.maxBitsPerDimension(); int[] dStack = new int[mMax]; BitVector[] eStack = new BitVector[mMax]; for (int i = 0; i < mMax; ++i) { eStack[i] = BitVectorFactories.OPTIMAL.apply(n); } if (!visitor.visit(mMax, index, p)) { return; } if (mMax != 0) { rBuffer[mMax - 1].clear(); } int[] ik = new int[2]; for (int i = mMax; --i >= 0; ) { masks.copyMaskTo(i, d, mu); computeInverseBits(d, mu, e, rBuffer[i], wAndT); copyOneBitToEachDimensionWhereSet(t, i, p); dStack[i] = d; eStack[i].copyFrom(e); int oldD = d; d = updateD(d, w); k -= masks.getCardinality(i); updateE(oldD, w, e); index.copySectionFrom(k, rBuffer[i]); boolean wantsChildren = visitor.visit(i, index, p); if (wantsChildren & i != 0) { rBuffer[i - 1].clear(); } else { ik[0] = i; ik[1] = k; assert (i == 0) == (k == 0); goUpWhileNeeded(p, dStack, eStack, ik, index); i = ik[0]; k = ik[1]; d = dStack[i - 1]; e.copyFrom(eStack[i - 1]); boolean incremented = rBuffer[i - 1].increment(); if (!incremented) { assert i == mMax; break; } } } } CompactHilbertCurve(MultiDimensionalSpec spec);  CompactHilbertCurve(int[] m); @Override MultiDimensionalSpec getSpec(); @Override void index(BitVector[] p, int minLevel, BitVector index); @Override void indexInverse(BitVector index, BitVector[] p); @Override void accept(ZoomingNavigator visitor); @Override String toString();  }
@Test public void twoDimensionsOfOrder3AndOrder1Respectively() { CompactHilbertCurve chc = new CompactHilbertCurve(new int[] {3, 1}); ZoomingNavigator mock = EasyMock.createStrictMock(ZoomingNavigator.class); EasyMock.expect(mock.visit(EasyMock.eq(3), EasyMock.eq(TestUtils.createBitVector(0, 4)), EasyMock.aryEq(new BitVector[] { TestUtils.createBitVector(0, 3), TestUtils.createBitVector(0, 1)}))).andReturn(true); EasyMock.expect(mock.visit(EasyMock.eq(2), EasyMock.eq(TestUtils.createBitVector(0, 4)), EasyMock.aryEq(new BitVector[] { TestUtils.createBitVector(0, 3), TestUtils.createBitVector(0, 1)}))).andReturn(true); EasyMock.expect(mock.visit(EasyMock.eq(1), EasyMock.eq(TestUtils.createBitVector(0, 4)), EasyMock.aryEq(new BitVector[] { TestUtils.createBitVector(0, 3), TestUtils.createBitVector(0, 1)}))).andReturn(false); EasyMock.expect(mock.visit(EasyMock.eq(1), EasyMock.eq(TestUtils.createBitVector(4, 4)), EasyMock.aryEq(new BitVector[] { TestUtils.createBitVector(2, 3), TestUtils.createBitVector(0, 1)}))).andReturn(true); EasyMock.expect(mock.visit(EasyMock.eq(0), EasyMock.eq(TestUtils.createBitVector(4, 4)), EasyMock.aryEq(new BitVector[] { TestUtils.createBitVector(2, 3), TestUtils.createBitVector(0, 1)}))).andReturn(kAnyBoolean); EasyMock.expect(mock.visit(EasyMock.eq(0), EasyMock.eq(TestUtils.createBitVector(5, 4)), EasyMock.aryEq(new BitVector[] { TestUtils.createBitVector(3, 3), TestUtils.createBitVector(0, 1)}))).andReturn(kAnyBoolean); EasyMock.expect(mock.visit(EasyMock.eq(0), EasyMock.eq(TestUtils.createBitVector(6, 4)), EasyMock.aryEq(new BitVector[] { TestUtils.createBitVector(3, 3), TestUtils.createBitVector(1, 1)}))).andReturn(kAnyBoolean); EasyMock.expect(mock.visit(EasyMock.eq(0), EasyMock.eq(TestUtils.createBitVector(7, 4)), EasyMock.aryEq(new BitVector[] { TestUtils.createBitVector(2, 3), TestUtils.createBitVector(1, 1)}))).andReturn(kAnyBoolean); EasyMock.expect(mock.visit(EasyMock.eq(2), EasyMock.eq(TestUtils.createBitVector(8, 4)), EasyMock.aryEq(new BitVector[] { TestUtils.createBitVector(4, 3), TestUtils.createBitVector(0, 1)}))).andReturn(true); EasyMock.expect(mock.visit(EasyMock.eq(1), EasyMock.eq(TestUtils.createBitVector(8, 4)), EasyMock.aryEq(new BitVector[] { TestUtils.createBitVector(4, 3), TestUtils.createBitVector(0, 1)}))).andReturn(false); EasyMock.expect(mock.visit(EasyMock.eq(1), EasyMock.eq(TestUtils.createBitVector(12, 4)), EasyMock.aryEq(new BitVector[] { TestUtils.createBitVector(6, 3), TestUtils.createBitVector(0, 1)}))).andReturn(false); EasyMock.replay(mock); chc.accept(mock); EasyMock.verify(mock); }