public static void ApplyZeroBlocks(string pathToFile, ZeroBlockList committedList, ZeroBlockList attemptingList) { using (FileStream stream = new FileStream(pathToFile, FileMode.Open, FileAccess.Write)) { foreach (ulong addr in committedList) { long seekAddr = stream.Seek((long)addr, SeekOrigin.Begin); if (seekAddr != (long)addr) { throw new InvalidOperationException("Unable to seek to the requested address."); } stream.Write(Zeros, 0, (int)Config.BlockSize); } foreach (ulong addr in attemptingList) { long seekAddr = stream.Seek((long)addr, SeekOrigin.Begin); if (seekAddr != (long)addr) { throw new InvalidOperationException("Unable to seek to the requested address."); } stream.Write(Zeros, 0, (int)Config.BlockSize); } } }
public Experiment(ZeroBlockList committedList, ZeroBlockList attemptingList) { // Assign an experiment number and increment the global counter. _experimentNumber = ExperimentCounter++; // Save the zero block lists. _committedList = committedList; _attemptingList = attemptingList; }
public void Complete() { if (Succeeded) { ZeroBlockList committedList = new ZeroBlockList(); committedList.AddRange(_committedList); committedList.AddRange(_attemptingList); _committedList = committedList; _attemptingList = new ZeroBlockList(); } Delete(); }
private Experiment[] GeneratePermutations(Experiment baseExperiment, int numExperiments) { Log(baseExperiment, $"Generating {numExperiments} experiments based on this successful experiment."); Experiment[] experiments = new Experiment[numExperiments]; for (int i = 0; i < numExperiments; i++) { // Generate the next block list. ZeroBlockList attemptingList = new ZeroBlockList(); while (true) { ulong value = GenerateRandomBlock(); if (!baseExperiment.CommittedList.Contains(value)) { attemptingList.Add(value); break; } } // Create a new experiment. experiments[i] = new Experiment(baseExperiment.CommittedList, attemptingList); } return(experiments); }
private ZeroBlockList(ZeroBlockList list) { _set.UnionWith(list); }