Thank you and one question/suggestion #96
Replies: 1 comment 6 replies
-
Hi Didier, Thank you for your feedback! I am glad that you like this library. Regarding your question, the _get_at method is indeed a get existing entry or create a new one method. For an "insert or update" action, this method is quite useful and simplify the design. You need t call _get_at method and then update the returned entry. Here is an example with an associative array of int -->int:
This works since the _init method of an int initializes the object to 0. By the way, did you try your own implementation of the k-nucleotide benchmark or the one from https://github.com/P-p-H-d/mlib/tree/master/bench/nucleotide ? |
Beta Was this translation helpful? Give feedback.
-
Bonjour Patrick et félicitations pour ce précieux travail!
I have a question/suggestion regarding the _get_at method (it came in in the
context of an OA dict - that function is not listed for dict containers in the
readme.md but is it present in m-dict.h and listed in Container.ods).
In Container.ods it is listed as a GET SET KEY method. My understanding of the
present implementation in m-dict.h is that it is instead a "GET OR INIT" method.
The case I have in mind is the situation where one wants to perform an
"insert_or_update" action with only one hashing (thus avoiding a _get
followed by a _set_at).
I presume one classical way to do it is through a f(dict, key, value) where f
If the returned pointer is not NULL, one does the appropriate update of the orig_value by
de-referencing it.
My question is : Is the _get_at function [for dict] the relevant function inside mlib for such a use case ? or
did I missed another one ? (since it always returns a valid pointer one needs to circumvent the ambiguity if
either a) the key was already present with an associated value being equal to the init value of
valuetype, and b) the key was not present).
Thank you!
Didier
[Side note: by curiosity I tested mlib for a pure C implementation of the k-nucleotide benchmark game, it was on
par with the one being ranked first and based on gnu pb_ds.]
Beta Was this translation helpful? Give feedback.
All reactions