Exemplo n.º 1
0
        public void AllXesGives36Nodes()
        {
            var mask   = BitMask.FromString("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
            var memPos = MemoryPosition.FromString("111111111111111111111111111111111111");

            memPos = mask.Apply(memPos);

            var topNode = new UnsplitNode();

            topNode.SetValue(memPos, 0, MemoryValue.FromLong(1));

            Assert.AreEqual(36, topNode.GetTreeSize());
        }
Exemplo n.º 2
0
        public void SmallerTest()
        {
            Memory.REGISTER_SIZE = 6;

            var mem = new Memory(2);

            var bitMask = BitMask.FromString("X1001X");
            var memPos  = MemoryPosition.FromLong(42);
            var memVal  = MemoryValue.FromLong(100);

            mem.SetMask(bitMask);
            mem.SetValue(memPos, memVal);

            Assert.AreEqual(400, mem.GetSummedValue());
        }
Exemplo n.º 3
0
        public void SetValue(MemoryPosition memPosition, MemoryValue value)
        {
            if (chipVersion == 1)
            {
                value = bitMask.Apply(value);
            }
            if (chipVersion == 2)
            {
                memPosition = bitMask.Apply(memPosition);
            }

            if (memRoot.ShouldSplit(memPosition, 0))
            {
                memRoot = memRoot.Split();
            }
            memRoot.SetValue(memPosition, 0, value);
        }
Exemplo n.º 4
0
        public void SetValue(MemoryPosition memoryPosition, int memoryPointer, MemoryValue value)
        {
            if (memoryPointer == Memory.REGISTER_SIZE)
            {
                Value = value;
            }
            else
            {
                if (Child == null)
                {
                    Child = new UnsplitNode();
                }

                if (Child.ShouldSplit(memoryPosition, memoryPointer + 1))
                {
                    Child = Child.Split();
                }
                Child.SetValue(memoryPosition, memoryPointer + 1, value);
            }
        }
Exemplo n.º 5
0
        public void SetValue(MemoryPosition memoryPosition, int memoryPointer, MemoryValue value)
        {
            // splitnode should never be a leaf

            bool?memoryAction = memoryPosition.GetAction(memoryPointer);

            bool toZero, toOne;

            if (memoryAction.HasValue)
            {
                toOne  = memoryAction.Value;
                toZero = !toOne;
            }
            else
            {
                toOne  = true;
                toZero = true;
            }

            if (toZero)
            {
                if (Zero.ShouldSplit(memoryPosition, memoryPointer + 1))
                {
                    Zero = Zero.Split();
                }
                Zero.SetValue(memoryPosition, memoryPointer + 1, value);
            }
            if (toOne)
            {
                if (One.ShouldSplit(memoryPosition, memoryPointer + 1))
                {
                    One = One.Split();
                }
                One.SetValue(memoryPosition, memoryPointer + 1, value);
            }
        }