Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This is chopped up to only be the relevant code of course.
- iterator mitems*[T](a: var seq[T]): var T {.inline.} =
- var i = 0
- let L = len(a)
- while i < L:
- yield a[i]
- inc(i)
- assert(len(a) == L, "seq modified while iterating over it")
- type
- MemoryCell* = object
- id*: int
- data*: CellData
- Memory* = seq[ref MemoryCell]
- Link* = object
- source*: MemoryCell
- dest*: MemoryCell
- Links* = seq[Link]
- proc reverse*(links: var Links) =
- # reverses data flow in links
- for link in links.mitems:
- swap(link.source, link.dest) # What happens here? Is this the right way to do what I want? Is this needless copying?
- # If I had refs, would the instance count keep rising with the swap or neatly swap the pointers which is what I want ideally.
- # Am I better off using effects to manage this?
Advertisement
Add Comment
Please, Sign In to add comment