Esempio n. 1
0
        public void FirstInBlockTest()
        {
            // At level 0, each block contains one cell:
            Assert.Equal(0UL, ZCurve.FirstInBlock(0, 0));
            Assert.Equal(1UL, ZCurve.FirstInBlock(1, 0));
            Assert.Equal(2UL, ZCurve.FirstInBlock(2, 0));
            Assert.Equal(3UL, ZCurve.FirstInBlock(3, 0));
            Assert.Equal(4UL, ZCurve.FirstInBlock(4, 0));
            Assert.Equal(1234567890UL, ZCurve.FirstInBlock(1234567890, 0));
            Assert.Equal((ulong)(long.MaxValue), ZCurve.FirstInBlock(long.MaxValue, 0));

            Assert.Equal(0UL, ZCurve.FirstInBlock(0, 1));
            Assert.Equal(0UL, ZCurve.FirstInBlock(1, 1));
            Assert.Equal(0UL, ZCurve.FirstInBlock(2, 1));
            Assert.Equal(0UL, ZCurve.FirstInBlock(3, 1));
            Assert.Equal(4UL, ZCurve.FirstInBlock(4, 1));
            Assert.Equal(0x499602d0UL, ZCurve.FirstInBlock(0x499602d2, 1));
            Assert.Equal((ulong)(long.MaxValue - 3), ZCurve.FirstInBlock(long.MaxValue, 1));

            Assert.Equal(0UL, ZCurve.FirstInBlock(0, 20));
            Assert.Equal(0UL, ZCurve.FirstInBlock(1, 20));
            Assert.Equal(0UL, ZCurve.FirstInBlock(2, 20));
            Assert.Equal(0UL, ZCurve.FirstInBlock(3, 20));
            Assert.Equal(0UL, ZCurve.FirstInBlock(4, 20));
            Assert.Equal(0UL, ZCurve.FirstInBlock(0x499602d2, 20));
            Assert.Equal(0x7fffff0000000000UL, ZCurve.FirstInBlock(long.MaxValue, 20));

            Assert.Equal(0x4000000000000000UL, ZCurve.FirstInBlock(long.MaxValue, 31));
            Assert.Equal(0UL, ZCurve.FirstInBlock(long.MaxValue, 32));
        }
Esempio n. 2
0
        public void BlockPropertyTest(ulong z, int level, ulong first, ulong last)
        {
            int   i = ZCurve.LargestLevel(z);
            ulong f = ZCurve.FirstInBlock(z, i);
            ulong l = ZCurve.LastInBlock(z, i);
            ulong n = ZCurve.CellsPerBlock(i);

            Assert.Equal(level, i);
            Assert.Equal(first, f);
            Assert.Equal(last, l);

            _output.WriteLine($"z={z} i={i} first={f:X8} last={l:X8} cells_in_block={n}");
        }
Esempio n. 3
0
        public void QueryBlocksTrial()
        {
            // Expect shortest ordered sequence of blocks covering query box

            // Query box:
            ulong qlo = ZCurve.Encode(1U, 1U);             // 3
            ulong qhi = ZCurve.Encode(5U, 4U);             // 49

            // Expected result: 3 6 7 9 11 (12..15) 18 19 (24..27) 33 36 37 48 49
            var starts   = new ulong[] { 3, 6, 7, 9, 11, 12, 18, 19, 24, 33, 36, 37, 48, 49 };
            var levels   = new[] { 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0 };
            var expected = starts.Zip(levels, (s, l) => new ZCurve.Block(s, l)).ToList();
            var actual   = new List <ZCurve.Block>();

            ulong first = ZCurve.FirstInBlock(qlo, 0);
            ulong last  = ZCurve.FirstInBlock(qhi, 0);

            for (ulong cursor = first; ;)
            {
                int   level     = ZCurve.LargestLevel(cursor, last);
                ulong increment = ZCurve.CellsPerBlock(level);

                actual.Add(new ZCurve.Block(cursor, level));

                cursor += increment;

                if (cursor > last)
                {
                    break;
                }

                if (!ZCurve.IsInsideBox(cursor, first, last))
                {
                    cursor = ZCurve.NextInsideBox(cursor, first, last);
                }
            }

            Assert.Equal(expected, actual);
        }