Discussion of article "MQL5 Cookbook: Implementing an Associative Array or a Dictionary for Quick Data Access" - page 4
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
There may be several reasons for this. Most likely, either type incompatibility or incorrect handling of pointers. Also, we cannot exclude peculiarities of working with template methods (there are their own nuances there too).
In general, it is better to use a ready-made trading engine, you will save a lot of time and nerves: https://www.mql5.com/en/articles/2166.
Good afternoon! Can you tell me how to loop through the entire dictionary, removing pairs by a certain condition, something I can not catch up. Here is an example of such a task.
Good afternoon! Can you tell me how to loop through the entire dictionary, removing pairs by a certain condition, something I can not catch up. Here is an example of such a task.
Good question. Now I checked the deletion using your method - it does not work correctly. I will look into it.
Good question. I have now checked the deletion using your method - it does not work correctly. I'll look into it.
It should not work correctly in the general case.
The correct way to perform multiple deletions from an associative array is to collect an array of keys to be deleted, then delete by key.
it doesn't have to work correctly in general.
the correct way to perform multiple deletions from an associative array is to collect an array of keys to be deleted, then delete by key.
This is understandable, but again it is unnecessary work.
Good question. I have now checked the deletion using your method - it does not work correctly. I'll look into it.
Thanks for the response!
it doesn't have to work correctly in general.
the correct way to perform multiple deletions from an associative array is to collect an array of keys to be deleted, then delete by key.
That's the thing, even this method suddenly causes a strange bug. It's obviously an error. I will look into it.
For now, I can advise you to create a new dictionary, and add to it the values that do not need to be deleted. Then clear the old one. This will 100% work.
Here goes:
1. update the Dictionary version to the one attached to this post.
2. Run a test script to delete even elements.
Deletion should be done in two passes:
Regarding the DeleteCurrentObject() method:
This method should only be used in conjunction with the ContainsKey() function. The only reason why it is available as public is that in this case the method call saves time on repositioning the pointer. That is, the typical and only case of its use is 1. Check if there is a key, 2. If there is - delete it quickly with this method.
That's understandable, but again, unnecessary bodywork.
It is technically possible to do a one-pass removal as you expect. But it would be complicated. That's why not yet, only in two passes. From the point of view of the dictionary as a distributed data structure, two-pass deletion is a more canonically correct solution. It is only at the user level it seems that deletion is sequential, in reality everything is different. In terms of performance, single-pass deletion will not bring any benefits. In terms of convenience, yes, it may be more convenient.
It is technically possible to do a one-pass removal as you expect. But it would be complicated. That's why not yet, only in two passes. From the point of view of the dictionary as a distributed data structure, two-pass deletion is more canonically correct. It is only at the user level it seems that deletion is sequential, in reality everything is different. In terms of performance, single-pass deletion will not bring any benefits. In terms of convenience, yes, it may be more convenient.
Thanks.
I think I found a bug when deleting an element and trying to get to the last element:
Error in the CDictionary.mqh will be:
invalid pointer access in 'Dictionary.mqh' (463,9)
Can anyone confirm this? Any ideas how to fix?
It was a bug in line 500 && 501 on the implementation of checking the pointers.
Fixed using inbuilt CheckPointer().