Stable structure range length

Is there a more performant way to get to know the number of entries in the stable structure btreemap where keys belong to the specified range than my_btree_map.range().count()?

1 Like

That would be the way to do it. Having that said, this is currently inefficient because under the hood we deserialize all the values stored in that range. We can potentially change the implementation of range().count() to skip the deserialization and have it be more efficient. If that’s important to you, file an issue and we’ll take care of it :slight_smile:

5 Likes

Gotcha, thanks.

Issue opened :point_right: https://github.com/dfinity/stable-structures/issues/189

1 Like

Personally I keep a count “on the side” and update it with every insert/delete operation. If this were built in, that would help, of course! I do keep other aggregate stats as well, though, so I would have to keep this pattern even if count() were built in.

1 Like