Next returns the item on the right.
()
| 28 | |
| 29 | // Next returns the item on the right. |
| 30 | func (e *ListElement[Key, Value]) Next() *ListElement[Key, Value] { |
| 31 | for next := e.next.Load(); next != nil; { |
| 32 | // if the next item is not deleted, return it |
| 33 | if next.deleted.Load() == 0 { |
| 34 | return next |
| 35 | } |
| 36 | |
| 37 | // point current elements next to the following item |
| 38 | // after the deleted one until a non deleted or list end is found |
| 39 | following := next.Next() |
| 40 | if e.next.CompareAndSwap(next, following) { |
| 41 | next = following |
| 42 | } else { |
| 43 | next = next.Next() |
| 44 | } |
| 45 | } |
| 46 | return nil // end of the list reached |
| 47 | } |
no outgoing calls