Esempio n. 1
0
        private static Tuple <int, MemoryStream> RLEEncodeAddRun(int runLen, uint runId)
        {
            var output = new MemoryStream();

            using (var writer = new BinaryWriter7(output)) {
                writer.Write7BitEncodedInt(RUN_LENGTH_SHIFT + runLen);
                writer.Write(runId);
            }
            return(new Tuple <int, MemoryStream>(runLen, output));
        }
Esempio n. 2
0
        private static Tuple <int, MemoryStream> RLEEncodeAddRun(int runLen, uint[] runIds)
        {
            var output = new MemoryStream();

            using (var writer = new BinaryWriter7(output)) {
                writer.Write7BitEncodedInt(RUN_LENGTH_SHIFT + (runLen == -1 ? 1 : runLen));
                for (var i = -1; i >= runLen; i--)
                {
                    writer.Write(runIds[-i]);
                }
            }
            return(new Tuple <int, MemoryStream>(Math.Abs(runLen), output));
        }
Esempio n. 3
0
        public override void setBlock(int x, int y, int z, uint block) {
            var ind = index(x, y, z);
            var node = tree.FindGreatestNotGreater(ind);
            var offset = node.key;

            var runLen = 0;
            var runLenWrited = false;

            MemoryStream output = null;
            using (var reader = new BinaryReader7(new MemoryStream(node.data, 0, node.data.Length))) {
                using(var writer = new BinaryWriter7(output = new MemoryStream())) {
                    while (reader.BaseStream.Position != reader.BaseStream.Length) {
                        if (runLen == 0) {
                            runLen = reader.Read7BitEncodedInt() - RUN_LENGTH_SHIFT;
                            runLenWrited = false;
                        } else if (runLen > 0) {
                            var runId = reader.ReadUInt32();
                            // blocks in range [offset...offset+runLen) is runId
                            offset = offset + runLen;
                            if (ind < offset) {
                                writer.Write7BitEncodedInt(ind - (offset - runLen) + RUN_LENGTH_SHIFT);
                                writer.Write(runId);
                                writer.Write7BitEncodedInt(1 + RUN_LENGTH_SHIFT);
                                writer.Write(block);
                                if (offset - ind -1 > 0) {
                                    writer.Write7BitEncodedInt(offset - ind -1 + RUN_LENGTH_SHIFT);
                                    writer.Write(runId);
                                }
                            } else {
                                writer.Write7BitEncodedInt(runLen + RUN_LENGTH_SHIFT);
                                writer.Write(runId);
                            }
                            runLen = 0;
                        } else if (runLen < 0) {
                            var blockId = reader.ReadUInt32();

                            if(!runLenWrited) {
                                writer.Write7BitEncodedInt(runLen + RUN_LENGTH_SHIFT);
                                runLenWrited = true;
                            }
                            if (offset == ind) {
                                writer.Write(block);
                            } else {
                                writer.Write(blockId);
                            }
                            runLen++;
                            offset++;
                        }
                    }
                }
            }

            var newdata = output.ToArray();
            node.data = output.ToArray();
        }
Esempio n. 4
0
 private static Tuple<int, MemoryStream> RLEEncodeAddRun(int runLen, uint[] runIds) {
     var output = new MemoryStream();
     using (var writer = new BinaryWriter7(output)) {
         writer.Write7BitEncodedInt(RUN_LENGTH_SHIFT + (runLen == -1 ? 1 : runLen));
         for (var i = -1; i >= runLen; i--) {
             writer.Write(runIds[-i]);
         }
     }
     return new Tuple<int, MemoryStream>(Math.Abs(runLen), output);
 }
Esempio n. 5
0
 private static Tuple<int, MemoryStream> RLEEncodeAddRun(int runLen, uint runId) {
     var output = new MemoryStream();
     using (var writer = new BinaryWriter7(output)) {
         writer.Write7BitEncodedInt(RUN_LENGTH_SHIFT + runLen);
         writer.Write(runId);
     }
     return new Tuple<int, MemoryStream>(runLen, output);
 }
Esempio n. 6
0
        public override void setBlock(int x, int y, int z, uint block)
        {
            var ind    = index(x, y, z);
            var node   = tree.FindGreatestNotGreater(ind);
            var offset = node.key;

            var runLen       = 0;
            var runLenWrited = false;

            MemoryStream output = null;

            using (var reader = new BinaryReader7(new MemoryStream(node.data, 0, node.data.Length))) {
                using (var writer = new BinaryWriter7(output = new MemoryStream())) {
                    while (reader.BaseStream.Position != reader.BaseStream.Length)
                    {
                        if (runLen == 0)
                        {
                            runLen       = reader.Read7BitEncodedInt() - RUN_LENGTH_SHIFT;
                            runLenWrited = false;
                        }
                        else if (runLen > 0)
                        {
                            var runId = reader.ReadUInt32();
                            // blocks in range [offset...offset+runLen) is runId
                            offset = offset + runLen;
                            if (ind < offset)
                            {
                                writer.Write7BitEncodedInt(ind - (offset - runLen) + RUN_LENGTH_SHIFT);
                                writer.Write(runId);
                                writer.Write7BitEncodedInt(1 + RUN_LENGTH_SHIFT);
                                writer.Write(block);
                                if (offset - ind - 1 > 0)
                                {
                                    writer.Write7BitEncodedInt(offset - ind - 1 + RUN_LENGTH_SHIFT);
                                    writer.Write(runId);
                                }
                            }
                            else
                            {
                                writer.Write7BitEncodedInt(runLen + RUN_LENGTH_SHIFT);
                                writer.Write(runId);
                            }
                            runLen = 0;
                        }
                        else if (runLen < 0)
                        {
                            var blockId = reader.ReadUInt32();

                            if (!runLenWrited)
                            {
                                writer.Write7BitEncodedInt(runLen + RUN_LENGTH_SHIFT);
                                runLenWrited = true;
                            }
                            if (offset == ind)
                            {
                                writer.Write(block);
                            }
                            else
                            {
                                writer.Write(blockId);
                            }
                            runLen++;
                            offset++;
                        }
                    }
                }
            }

            var newdata = output.ToArray();

            node.data = output.ToArray();
        }