Link connects ring r with ring s such that r.Next() becomes s and returns the original value for r.Next(). r must not be empty. If r and s point to the same ring, linking them removes the elements between r and s from the ring. The removed elements form a subring and the result is a reference to th
(s *Ring[T])
| 86 | // last element of s after insertion. |
| 87 | // |
| 88 | func (r *Ring[T]) Link(s *Ring[T]) *Ring[T] { |
| 89 | n := r.Next() |
| 90 | if s != nil { |
| 91 | p := s.Prev() |
| 92 | // Note: Cannot use multiple assignment because |
| 93 | // evaluation order of LHS is not specified. |
| 94 | r.next = s |
| 95 | s.prev = r |
| 96 | n.prev = p |
| 97 | p.next = n |
| 98 | } |
| 99 | return n |
| 100 | } |
| 101 | |
| 102 | // Unlink removes n % r.Len() elements from the ring r, starting |
| 103 | // at r.Next(). If n % r.Len() == 0, r remains unchanged. |