コード例 #1
0
        private static LinkedNode BuildList(byte[] primeData)
        {
            LinkedNode root;

            root = new LinkedNode(256, 1);
            root = root.Insert(new LinkedNode(257, 1));

            for (var i = 0; i < primeData.Length; i++)
            {
                if (primeData[i] != 0)
                {
                    root = root.Insert(new LinkedNode(i, primeData[i]));
                }
            }

            return(root);
        }
コード例 #2
0
        private static LinkedNode Decode(BitStream input, LinkedNode head)
        {
            var node = head;

            while (node.Child0 != null)
            {
                var bit = input.ReadBits(1);
                if (bit == -1)
                {
                    throw new InvalidDataException($"Unexpected end of file");
                }

                node = bit == 0 ? node.Child0 ! : node.Child1 !;
            }

            return(node);
        }