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

Add option to insert list in ets:insert, ets:lookup refactor #1405

Merged

Conversation

TheSobkiewicz
Copy link
Contributor

@TheSobkiewicz TheSobkiewicz commented Dec 17, 2024

Changes:

  • Enabled ets:insert/2 to accept lists for bulk insertion.
  • Extracted helper functions for ets:lookup/2 and ets:insert/2 that do not apply table locks.

Use Cases for the Helper Functions:

The new helper functions can be utilized in the following ETS operations to reduce code duplication:

  • ets:update_element/3
  • ets:insert_new/2
  • ets:update_counter/3
  • ets:update_counter/4
  • ets:take/2
  • ets:delete_object/2

Every mentioned function will be implemented after merging of this PR.

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later

@TheSobkiewicz TheSobkiewicz force-pushed the thesobkiewicz/nifs/ets/refactor_insert branch 4 times, most recently from 76774f0 to 6ac7831 Compare January 9, 2025 15:44
@TheSobkiewicz TheSobkiewicz force-pushed the thesobkiewicz/nifs/ets/refactor_insert branch 3 times, most recently from f54ef62 to 45eccdc Compare January 15, 2025 16:13
@TheSobkiewicz TheSobkiewicz force-pushed the thesobkiewicz/nifs/ets/refactor_insert branch from 45eccdc to e5908a2 Compare January 16, 2025 12:56
Copy link
Collaborator

@bettio bettio left a comment

Choose a reason for hiding this comment

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

Still few minor changes are required, thanks for this work so far.

@TheSobkiewicz TheSobkiewicz force-pushed the thesobkiewicz/nifs/ets/refactor_insert branch 3 times, most recently from 387dc1c to 54951ff Compare January 20, 2025 14:25
@bettio
Copy link
Collaborator

bettio commented Jan 22, 2025

I'm sorry about this additional round of comments, hope they can be somehow interesting to you and not just boring nitpicking.
Thanks for the contribution so far ❤️.

@TheSobkiewicz
Copy link
Contributor Author

I'm sorry about this additional round of comments, hope they can be somehow interesting to you and not just boring nitpicking. Thanks for the contribution so far ❤️.

Don't worry, thank you for your patience when reviewing it ❤️

@TheSobkiewicz TheSobkiewicz force-pushed the thesobkiewicz/nifs/ets/refactor_insert branch 3 times, most recently from 6e249eb to 0f71f40 Compare January 22, 2025 17:39
@bettio
Copy link
Collaborator

bettio commented Jan 25, 2025

I resolved open points I believe are still open. After that we are good I think. I would appreciate also a check from @jakub-gonet

@jakub-gonet
Copy link
Contributor

@bettio done. Found mostly nits and one missing free.

@TheSobkiewicz TheSobkiewicz force-pushed the thesobkiewicz/nifs/ets/refactor_insert branch 3 times, most recently from 74dd710 to 4d84859 Compare January 27, 2025 10:36
@TheSobkiewicz TheSobkiewicz force-pushed the thesobkiewicz/nifs/ets/refactor_insert branch from 4d84859 to 8103fe7 Compare January 27, 2025 13:31
@TheSobkiewicz TheSobkiewicz requested a review from bettio February 3, 2025 11:55
Copy link
Collaborator

@bettio bettio left a comment

Choose a reason for hiding this comment

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

There is one last thing I suggest to change, after that just git rebase main and let's merge it (after a CI run).

Comment on lines 106 to 103
struct HNode *new_node = malloc(sizeof(struct HNode));
if (IS_NULL_PTR(new_node)) {
memory_destroy_heap(&heap, global);
return NULL;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why we don't move this block to the beginning of this function?
e.g.

struct HNode *ets_hashtable_new_node(term entry, int keypos, GlobalContext *global)
{
    struct HNode *new_node = malloc(sizeof(struct HNode));
    if (IS_NULL_PTR(new_node)) {
        return NULL;
    }

    size_t size = (size_t) memory_estimate_usage(entry);
    if (memory_init_heap(&new_node->heap, size) != MEMORY_GC_OK) {
        free(new_node);
        return NULL;
    }
   term new_entry = memory_copy_term_tree(&heap, entry);

   [...]

so we can avoid doing new_node->heap = heap that doesn't smell really good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, we are also able to reduce the number of function arguments in this way.

Signed-off-by: Tomasz Sobkiewicz <tomasz.sobkiewicz@swmansion.com>
@TheSobkiewicz TheSobkiewicz force-pushed the thesobkiewicz/nifs/ets/refactor_insert branch from ac07f46 to 3e0cc65 Compare February 13, 2025 11:56
Signed-off-by: Tomasz Sobkiewicz <tomasz.sobkiewicz@swmansion.com>
@TheSobkiewicz TheSobkiewicz force-pushed the thesobkiewicz/nifs/ets/refactor_insert branch from 3e0cc65 to 7640eaa Compare February 13, 2025 12:03
@bettio bettio merged commit 652d60e into atomvm:main Feb 14, 2025
109 checks passed
bettio added a commit that referenced this pull request Feb 17, 2025
…date_counter

Add ets:update_counter

Currently this solution doesn't support list of UpdateOp to update multiple counters.
Based on:
#1405

https://www.erlang.org/docs/23/man/ets#update_counter-3

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
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.

3 participants