public int CompareTo(DynamicEdge <T> other)
 {
     if (level != other.level)
     {
         return(level - other.level);
     }
     return(key - other.key);
 }
        /// <summary>
        /// Remove edge from adjacent list
        /// </summary>
        public void RemoveEdge(DynamicEdge <T> edge)
        {
            var adj = adjacent;
            int idx = EdgeListUtility.Index(adj, edge);

            adj.RemoveAt(idx);
            // Check if flag needs to be updated
            if (!((idx < adj.Count && adj[idx].level == edge.level) ||
                  (idx > 0 && adj[idx - 1].level == edge.level)))
            {
                euler[edge.level].SetFlag(false);
            }
        }
        public DynamicEdge <T> Link(DynamicVertex <T> other, T value)
        {
            var e = new DynamicEdge <T>(value, KeyCounter, this, other);

            KeyCounter++;
            if (!euler[0].IsConnected(other.euler[0]))
            {
                e.LinkSpanningForests();
            }
            euler[0].SetFlag(true);
            other.euler[0].SetFlag(true);
            EdgeListUtility.InsertEdge(adjacent, e);
            EdgeListUtility.InsertEdge(other.adjacent, e);
            return(e);
        }
        private static int GetUpperBound <T>(List <DynamicEdge <T> > list, DynamicEdge <T> edge)
        {
            int low  = -1;
            int high = list.Count;

            while (low + 1 < high)
            {
                int mid  = (low + high) >> 1;
                int comp = list[mid].CompareTo(edge);
                if (comp > 0)
                {
                    high = mid;
                }
                else
                {
                    low = mid;
                }
            }
            return(high);
        }
 public static void RemoveEdge <T>(List <DynamicEdge <T> > list, DynamicEdge <T> edge)
 {
     list.RemoveAt(Index(list, edge));
 }
        public static int Index <T>(List <DynamicEdge <T> > list, DynamicEdge <T> edge)
        {
            int idx = GetUpperBound(list, edge);

            return(idx - 1);
        }
 public static void InsertEdge <T>(List <DynamicEdge <T> > list, DynamicEdge <T> edge)
 {
     list.Insert(GetUpperBound(list, edge), edge);
 }