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()); }
public bool ShouldSplit(MemoryPosition memoryPosition, int memoryPointer) { if (memoryPointer == Memory.REGISTER_SIZE) { return(false); } if (memoryPosition.GetAction(memoryPointer) != null) { return(true); } return(false); }
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()); }
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); }
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); } }
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); } }
public bool ShouldSplit(MemoryPosition memoryPosition, int memoryPointer) => false;