Skip to content

Commit 39c62e1

Browse files
committed
docs: add some info about the implementation
1 parent 910498d commit 39c62e1

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

src/neighbours.jl

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -299,22 +299,25 @@ function old_new_cell(system::Particles, i, neighbour_list::LinkedList)
299299
return c, c2
300300
end
301301

302+
""" This struct is used to iterate over neighbours of a Linked list
303+
"""
302304
struct LinkedIterator
303305
neighbour_cells::Vector{Int}
304306
head::Vector{Int}
305307
list::Vector{Int}
306308
end
307309

310+
# To iterate over the neighbours of a linked list, one could write the following loops
311+
#@inbounds for c in neighbour_list.neighbour_cells
312+
# j = neighbour_list.head[c]
313+
# while (j != -1)
314+
# do stuff
315+
# j = neighbour_list.list[j]
316+
# end
317+
#end
318+
# This is however impossible to rewrite as a simple generator
319+
# So we implement the following function, which uses a state to carry over the needed information
308320
function Base.iterate(neighbour_list::LinkedIterator, state=-1)
309-
310-
#@inbounds for c in neighbour_list.neighbour_cells
311-
# j = neighbour_list.head[c]
312-
# while (j != -1)
313-
# do stuff
314-
# j = neighbour_list.list[j]
315-
# end
316-
#end
317-
318321
# First time in
319322
if state == -1
320323
next = iterate(neighbour_list.neighbour_cells)

0 commit comments

Comments
 (0)