Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Closed
@czgdp1807

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)

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