Zulip Chat Archive

Stream: new members

Topic: fast data structures?


Kevin Lacker (Oct 27 2020 at 18:14):

While trying to clean up this implementation of rewrite_search I am trying to figure out which data structures are the fastest and had a couple questions. I would expect that it's the ones implemented in the VM. It looks like d_array is supposed to be, for example. My first question is, does this work quickly as I'd expect? When I look at the code some of the methods don't seem like they would be efficient. For example from https://github.com/leanprover-community/lean/blob/0ec2a19/library/init/data/array/basic.lean#L11:

/-- `write a i v` sets the `i`th member of `a` to be `v`. Has builtin VM implementation. -/
def write (a : d_array n α) (i : fin n) (v : α i) : d_array n α :=
{data := λ j, if h : i = j then eq.rec_on h v else a.read j}

That implementation looks like it will be O(n) to evaluate a read after doing n writes. Is it actually being replaced with something else more efficient by the VM?

My second question is whether there are other efficient data structures. In particular a good map structure like a hashmap or a treemap would be nice. There are a bunch of different tree-like structures lying around and I was wondering if there's conventional wisdom on which are the best to use.

Mario Carneiro (Oct 27 2020 at 18:46):

Is it actually being replaced with something else more efficient by the VM?

yes

Mario Carneiro (Oct 27 2020 at 18:46):

There is an array-based hashmap implementation in mathlib

Bryan Gin-ge Chen (Oct 27 2020 at 18:46):

The conversation moved here


Last updated: Dec 20 2023 at 11:08 UTC