示例#1
0
 protected ImmutableState(ImmutableState prev, Register register, ushort value)
 {
     _memory = prev._memory;
     _regs = prev._regs.Set((int)register, value);
     _deviceStates = prev._deviceStates;
     _memoryMap = prev._memoryMap;
 }
 void InitializeFrames(int startIndex)
 {
     inputFrameDeltas      = new PersistentArray <InputFrameDelta>(FrameSyncConstant.DEFAULT_FRAMES_CHUNK_SIZE, startIndex);
     inputFrames           = new PersistentArray <InputFrame>(FrameSyncConstant.DEFAULT_FRAMES_CHUNK_SIZE, startIndex);
     systemDataFrames      = new PersistentArray <SWSystemDataFrame>(FrameSyncConstant.DEFAULT_SYSTEM_DATA_CHUNK_SIZE, startIndex);
     localInputFrameDeltas = new PersistentArray <InputFrameDelta>(FrameSyncConstant.DEFAULT_FRAMES_CHUNK_SIZE, 0);
 }
示例#3
0
 public ImmutableState()
 {
     _memory = new PersistentArray<ushort>(Dcpu.MAX_ADDRESS + 1);
     _regs = new PersistentArray<ushort>(11);
     _deviceStates = new Dictionary<string, DeviceState>();
     _memoryMap = new MemoryMap();
 }
示例#4
0
 protected ImmutableState(ushort[] memory)
 {
     _memory = new PersistentArray<ushort>(memory);
     _regs = new PersistentArray<ushort>(11);
     _deviceStates = new Dictionary<string, DeviceState>();
     _memoryMap = new MemoryMap();
 }
示例#5
0
        public void Delete(int length)
        {
            PersistentArray prevArray = this.history.Peek();
            PersistentArray newArray  = new PersistentArray(prevArray);

            newArray.Delete(length);
            this.history.Push(newArray);
        }
示例#6
0
        public void Append(string s)
        {
            PersistentArray prevArray = this.history.Peek();
            PersistentArray newArray  = new PersistentArray(prevArray);

            newArray.Append(s);
            this.history.Push(newArray);
        }
示例#7
0
 protected ImmutableState(ImmutableState prev, IEvent e)
 {
     _memory = prev._memory;
     _regs = prev._regs;
     _memoryMap = prev._memoryMap;
     _deviceStates = new Dictionary<string, DeviceState>(prev._deviceStates);
     _deviceStates[e.DeviceId] = _deviceStates[e.DeviceId].Handle(e);
 }
示例#8
0
 public void ConstructFromSourceArray()
 {
     var source = new int[60];
     for (int i=0; i < source.Length; ++i)
         source[i] = i * 3;
     var array = new PersistentArray<int>(source);
     for (int i=0; i < source.Length; ++i)
         Assert.AreEqual(source[i], array[i]);
 }
示例#9
0
 protected ImmutableState(ImmutableState prev, ushort from, ushort to, DeviceState device)
 {
     _memory = prev._memory;
     _regs = prev._regs;
     _memoryMap = new MemoryMap(prev._memoryMap);
     _memoryMap.Map(from, to, device.Id);
     _deviceStates = new Dictionary<string,DeviceState>(prev._deviceStates);
     _deviceStates[device.Id] = device;
 }
示例#10
0
 protected ImmutableState(ImmutableState prev, ushort addr, ushort value)
 {
     _memory = prev._memory;
     _regs = prev._regs;
     _memoryMap = prev._memoryMap;
     var deviceId = prev._memoryMap[addr];
     if (deviceId == null) {
         _memory = _memory.Set(addr, value);
         _deviceStates = prev._deviceStates;
     } else {
         _deviceStates = new Dictionary<string, DeviceState>(prev._deviceStates);
         _deviceStates[deviceId] = prev._deviceStates[deviceId].Write(addr, value);
     }
 }
示例#11
0
        public void CouldGrowParallel()
        {
            var da2 = new PersistentArray <long>("../PersistentArrayTests.CouldGrowParallel", 10000);
            var t   = Task.Run(() => {
                da2.Grow(3000);
                da2[43] = 43;
            });

            Thread.Sleep(1000);
            var da = new PersistentArray <long>("../PersistentArrayTests.CouldGrowParallel", 10000);

            da[42] = 42;
            da.Grow(300000);
            Assert.AreEqual(43, da2[43]);
            t.Wait();
            da2.Grow(3000000);
            Assert.AreEqual(42, da[42]);
        }
示例#12
0
        public void GetAndSet_ManyElementArray_CorrectElementsReturned()
        {
            var array = new PersistentArray<int>(100);
            for (int i=0; i < 100; ++i) {
                array = array.Set(i, 2 * i);
            }

            for (int i=0; i < 100; ++i) {
                Assert.AreEqual(2 * i, array[i]);
            }

            var array2 = array;
            for (int i=0; i < 100; ++i) {
                array2 = array2.Set(i, array[99 - i]);
            }

            for (int i=99; i >= 0; --i) {
                Assert.AreEqual(2 * i, array2[99 - i]);
            }
        }
    public PersistentArray <T> Set(int i, T v)
    {
        var nd   = root.DeepCopy();
        var mask = MSB(++i) - 1;
        var r    = new PersistentArray <T>(nd, Length);

        while (mask >= 0)
        {
            if ((1 & i >> mask) == 0)
            {
                nd = nd.lft = nd.lft.DeepCopy();
            }
            else
            {
                nd = nd.rgt = nd.rgt.DeepCopy();
            }
            mask--;
        }
        nd.dat = v;
        return(r);
    }
示例#14
0
        public void CouldCreateAndGrowDirectArray()
        {
            var da = new PersistentArray <long>("../PersistentArrayTests.CouldCreateAndGrowDirectArray", 100);

            da[42] = 24;
            da.Grow(200);
            Assert.AreEqual(24, da[42]);
            var count = 1000000;

            da.Grow(count);
            for (int rounds = 0; rounds < 10; rounds++)
            {
                var sw = new Stopwatch();
                sw.Start();
                for (int i = 0; i < count; i++)
                {
                    da[i] = i;
                }
                sw.Stop();
                Console.WriteLine($"Elapsed msec: {sw.ElapsedMilliseconds}");
            }
        }
示例#15
0
 protected KeyboardState(KeyboardState prev, PersistentArray<ushort> ringBuffer)
     : base(prev)
 {
     _ringBuffer = ringBuffer;
 }
示例#16
0
 public PersistentArray(PersistentArray array)
 {
     this.Length = array.Length;
     this.Root   = array.Root;
 }
示例#17
0
 public void Set_LengthOneArray_NewValueCorrect()
 {
     var array = new PersistentArray<string>(1);
     var array2 = array.Set(0, "foo");
     Assert.AreEqual("foo", array2[0]);
 }
示例#18
0
 public void Set_LengthOneArray_OldValueIdentical()
 {
     var array = new PersistentArray<string>(1);
     var array2 = array.Set(0, "foo");
     Assert.AreEqual(null, array[0]);
 }
示例#19
0
 protected DisplayState(DisplayState prev)
     : base(prev)
 {
     _displayMemory = prev._displayMemory;
 }
示例#20
0
 public DisplayState()
 {
     _displayMemory = new PersistentArray<ushort>(Width * Height);
 }
示例#21
0
 public KeyboardState()
 {
     _ringBuffer = new PersistentArray<ushort>(BufferLength + 1);
 }