← 输入框|github.com|刷新
Skip to content

Support reserve like std::vector<T>::reserve in C++ #2232

Closed

Description

@czgdp1807

It looks like reserve makes a big difference here, so we should support it in LPython as well. For example by from lpython import reserve and just call this function. The CPython implementation will not do anything.

Here is how to use it:

from lpython import reserve
def dijkstra_shortest_path(n: i32, source: i32) -> i32:
    i: i32; j: i32; v: i32; u: i32; mindist: i32; alt: i32; dummy: i32; uidx: i32
    dist_sum: i32;
    graph: list[i32] = []
    dist: list[i32] = []
    reserve(graph, n*n)

In CPython emulation this will be an empty function (no-op), in LPython we reserve the memory for this list, similar to reserve in C++, for performance.

Originally posted by @certik in #2231 (comment)

Activity

  1. czgdp1807 commented on Jul 30, 2023

    @czgdp1807
    CollaboratorAuthor

    @kabra1110 Please keep it a high priority so that we can benchmark it against equivalent C++ code in #2231.

  2. certik commented on Jul 30, 2023

    @certik
    Contributor

    Duplicate of #2233.

  3. changed the title [-]Support `list_reserve` like `std::vector<T>::reserve` in C++[/-] [+]Support `reserve` like `std::vector<T>::reserve` in C++[/+] on Jul 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions