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(); } }
public ISet <uint> getNextIndicesOfNodeAsSet(CausalSetSystemBlock causalSystemBlock, uint nodeIdx) { uint[] nodeIndicesAsList = causalSystemBlock.nodes[(int)nodeIdx].next.Select(n => causalSystemBlock.indirectionArray[(int)n.value]).ToArray(); return(SetHelpers.toSet(nodeIndicesAsList)); }