public CausalSetNode copyShallow() { Ensure.ensureHard(content == null); CausalSetNode result = new CausalSetNode(); result.next = ListHelpers.copy(next); result.nodeIndexInParentSystemBlock = nodeIndexInParentSystemBlock; result.globalIndex = globalIndex; return(result); }
public CausalSetSystemBlock copyDeep() { CausalSetSystemBlock copyResult = new CausalSetSystemBlock(); copyResult.indirectionArray = ArrayHelpers.copy(indirectionArray); copyResult.indirectionCounter = indirectionCounter; copyResult.entryIndices = entryIndices != null?ListHelpers.copy(entryIndices) : null; foreach (CausalSetNode iteratorNode in nodes) { copyResult.nodes.Add(iteratorNode.copyDeep()); } return(copyResult); }
void linearizeInternal(CausalSetSystemBlock causalSystemBlock, IList <uint> linearization, bool recusive) { causalSystemBlock.updateEntryIndices(); // we calculate this always new because we don't care about performance for now IList <uint> indicesOfEntryNodes = causalSystemBlockAccessor.getEntryIndicesAsList(causalSystemBlock); IList <uint> openNodeIndices = ListHelpers.copy(indicesOfEntryNodes); ISet <uint> nodeIndicesInLinearization = new HashSet <uint>(); // set, bool values hae no meaning while (!openNodeIndices.isEmpty()) { uint currentCandidateNodeIndex; {// choose random element from openNodeIndices and remove uint candidateIndexOfOpenNodeIndices = (uint)random.Next(openNodeIndices.Count); currentCandidateNodeIndex = openNodeIndices[(int)candidateIndexOfOpenNodeIndices]; openNodeIndices.RemoveAt((int)candidateIndexOfOpenNodeIndices); } Ensure.ensureHard(!nodeIndicesInLinearization.Contains(currentCandidateNodeIndex)); nodeIndicesInLinearization.Add(currentCandidateNodeIndex); // if we can and should recurse down if (recusive && causalSystemBlock.nodes[(int)currentCandidateNodeIndex].content != null) { CausalSetSystemBlock childrenBlock = causalSystemBlock.nodes[(int)currentCandidateNodeIndex].content; linearizeInternal(childrenBlock, linearization, recusive); } else { // the global index must be valid linearization.Add(causalSystemBlock.nodes[(int)currentCandidateNodeIndex].globalIndex.Value); } ISet <uint> nextIndicesOfCurrentCandidate = SetHelpers.subtract(causalSystemBlockAccessor.getNextIndicesOfNodeAsSet(causalSystemBlock, currentCandidateNodeIndex), nodeIndicesInLinearization); openNodeIndices = SetHelpers.union(SetHelpers.toSet(openNodeIndices), nextIndicesOfCurrentCandidate).ToList(); } }