Skip to content

Tree.sites iterator isn't reversable #2117

@jeromekelleher

Description

@jeromekelleher

It would be good to make the Tree.sites method reversable so that we can get at the sites backwards when running through the trees in reverse.

You can always just do reversed(list(tree.sites())) at the moment, though.

While making the change, we should update the low-level API to return a numpy array of site IDs.

It's then a question of whether it's worth keeping the iterator behaviour or if we should just return a list of site objects. I guess there is potentially some performance creating Site objects lazily on demand, but most of the time we'll just be creating them one after another.

An option would be to create a SiteRange object which looks a bit like the TreeIterator but also supports __getitem__ and creates site objects on demand.

Any thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Python APIIssue is about the Python APIenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions