Has anyone solved today's with some ring in the `lists` module?

I did not quite see how to insert or remove in arbitrary spots, and ended up 
using a very simple singly linked list ring written by hand with ad-hoc API for 
the problem, together with a map label -> node:
    
    
    type
      Node = ref object of RootObj
        label: int
        next: Node
    
    proc hash(node: Node): Hash =
      node.label.hash
    
    proc deleteNext(node: var Node): Node =
      result = node.next
      node.next = node.next.next
    
    proc insertAfter(node: var Node, inode: var Node) =
      inode.next = node.next
      node.next = inode
    
    var label2node: Table[int, Node]
    ...
    
    
    Run

As you see, my solution manipulates only nodes, there is no object for the 
collection itself.

Any examples using the `lists` module?

Reply via email to