Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Remaining Map Host Functions #54

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

bbyalcinkaya
Copy link
Member

This PR implements the remaining four map host functions, completing the implementation for all map-related host functions.

  • map_key_by_pos , map_val_by_pos: access to keys or values in a map by their position (when the items are sorted by keys).
  • map_keys, map_vals : return the list of all keys or values in the map, sorted by keys.

For these positional access functions, the list of keys is sorted each time the function is called, and a lookup-by-index or full key list is returned. This approach may be costly but is acceptable as positional operations seem to be less common compared to standard key lookups.

Soroban maps are implemented as key-value pair lists sorted by their keys. Key lookups are performed via binary search. Although implementing maps as lists could simplify these operations, it would negatively impact the following:

  • Loss of fast key lookups, membership checks, and unification.
  • Built-in maps inherently enforce unique keys, which we would lose with a list-based implementation.

For these reasons, I have retained the use of built-in maps to prioritize performance for the most common operations. While the current design may incur overhead for positional operations, I believe it balances performance and usability effectively given the expected use cases.

@bbyalcinkaya bbyalcinkaya mentioned this pull request Dec 19, 2024
@bbyalcinkaya bbyalcinkaya marked this pull request as ready for review December 19, 2024 20:43
@bbyalcinkaya bbyalcinkaya requested a review from gtrepta December 19, 2024 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant