Skip to content

Add map delete, put, fetch type operations #13795

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

Merged
merged 3 commits into from
Sep 16, 2024

Conversation

gldubc
Copy link
Member

@gldubc gldubc commented Aug 26, 2024

  1. Add map_delete, map_fetch, map_put operations for map types

  2. Rework function map_split_on_key into two direct functions map_get and map_delete

  3. Add an optimization for map_difference.
    If we are doing the difference of an open map with a single key, we can directly compute the difference of that key in both maps to simplify the result.

  4. Also, added the possibility for map keys to be not_set() since it is used in map_delete.

end
end

def map_update_static_value(descr, key, type) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def map_update_static_value(descr, key, type) do
defp map_update_static_value(descr, key, type) do

end
end

def map_put_static_value(descr, key, type) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def map_put_static_value(descr, key, type) do
defp map_put_static_value(descr, key, type) do

end

# Directly inserts a key of a given type into every positive and negative map
def map_put_static(descr, key, type) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def map_put_static(descr, key, type) do
defp map_put_static(descr, key, type) do

case :maps.take(:dynamic, descr) do
:error ->
cond do
subtype?(descr, open_map([{key, term()}])) -> map_put_static(descr, key, type)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a more efficient way of checking this? Perhaps we could use map_fetch? Perhaps we could simplify this function with map_fetch?

@josevalim josevalim merged commit 66d44be into elixir-lang:main Sep 16, 2024
7 of 9 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@josevalim josevalim deleted the map-delete branch September 16, 2024 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants