コード例 #1
0
        /// <inheritdoc/>
        protected override void GetEdgeAndNextIndex(int currentIndex, out Edge edge, out int nextIndex, bool isIncoming)
        {
            LinkedEdgeSetItem item = m_edgeSetBuffer[currentIndex];

            if (isIncoming)
            {
                edge      = item.TargetEdge;
                nextIndex = item.NextTargetIncomingEdgeIndex;
            }
            else
            {
                edge      = item.SourceEdge;
                nextIndex = item.NextSourceOutgoingEdgeIndex;
            }
        }
コード例 #2
0
        private bool AddEdgeUnchecked(
            NodeId source,
            NodeId target,
            BufferPointer <NodeEdgeListHeader> targetInEdges,
            bool isLight,
            bool bulkAddingTargetIncoming)
        {
            BufferPointer <NodeEdgeListHeader> outEdges = OutEdges.GetBufferPointer(source.Value);

            var edgeSetItem = new LinkedEdgeSetItem(source, target, isLight);
            int index       = 0;

            if (!bulkAddingTargetIncoming)
            {
                ConcurrentBigSet <LinkedEdgeSetItem> .GetAddOrUpdateResult result =
                    m_edgeSet.GetOrAdd(edgeSetItem);

                if (result.IsFound)
                {
                    // Edge already existed
                    return(false);
                }

                index = result.Index;
            }
            else
            {
                index = m_edgeSet.ReservedNextIndex(m_edgeSetBuffer);
                m_edgeSetBuffer[index] = edgeSetItem;
            }

            // Update head index for in edges and out edges
            int inEdgesNext  = Interlocked.Exchange(ref targetInEdges.Buffer[targetInEdges.Index].FirstIndex, index);
            int outEdgesNext = Interlocked.Exchange(ref outEdges.Buffer[outEdges.Index].FirstIndex, index);

            var linkedEdgeSetItemPtr = m_edgeSetBuffer.GetBufferPointer(index);

            // Update next pointers
            linkedEdgeSetItemPtr.Buffer[linkedEdgeSetItemPtr.Index].NextTargetIncomingEdgeIndex = inEdgesNext;
            linkedEdgeSetItemPtr.Buffer[linkedEdgeSetItemPtr.Index].NextSourceOutgoingEdgeIndex = outEdgesNext;

            Interlocked.Increment(ref m_edgeCount);

            // Update edge counts
            targetInEdges.Buffer[targetInEdges.Index].InterlockedIncrementCount();
            outEdges.Buffer[outEdges.Index].InterlockedIncrementCount();
            return(true);
        }