Implement Remaining Map Host Functions #54
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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.