nope! I've written an implementation base on an array of linked lists, mapping string->Object.
but it still needs a couple of tweaks. Mainly..
1. The string hash function is calculated in mql - might be nice to call a DLL for performance.
2. The value object must be a subclass of my HashValue object. I wonder if there is an implicit parent class that I can use (like Java's Object class ?)
Here's my stab at it..
The Hash by default will 'adopt' the value objects. In which case it
will free the memory when they are no longer in the hash. This behaviour can be
disabled in the constructor.
Here is an example:
Hash *h = new Hash(); // Store values h.hPutInt("low",0); h.hPutInt("high",1); // Get values int high = h.hGetInt("high"); // Loop HashLoop *l ; for( l = new HashLoop(h) ; l.hasNext() ; l.next()) { string key = l.key(); int j = l.valInt(); Print(key," = ",j); } delete l; delete h;
Here's my stab at it..
The Hash by default will 'adopt' the value objects. In which case it
will free the memory when they are no longer in the hash. This can be
disabled in the constructor.
Here is an example:
It's very interesting, thank you for sharing. Maybe you can publish it to the codebase ?
I've submitted it just before posting here :)
I've made a tiny change - removed getSize() and replaced with
getSlots() -- size of table / number of linked lists -- not really useful to anything except the HashLoop object.
and getCount()-- number of entries in the hash
Here's my stab at it..
The Hash by default will 'adopt' the value objects. In which case it
will free the memory when they are no longer in the hash. This behaviour can be
disabled in the constructor.
Here is an example:
Your code is for mql5 and not for (even) mt4 600+ - correct?
@Ovo,I've not done any benchmarking on it, although I'm not 100% sure you mean - you mean performance for searching? At what point does using a hash function beat just comparing all strings blindly?
@gooly Nope mql4++ (or whatever we will call it :) )
I'd be interested to know if there is a better way to implement generic Objects for the value that is stored (eg void *, void &, or Java's Object etc) rather than using an explicit subclass as I have done (HashValue)
@Ovo,I've not done any benchmarking on it, although I'm not 100% sure you mean - you mean performance for searching? At what point does using a hash function beat just comparing all strings blindly?
Well, blindly, I meant in a sequence they were stored. For example for 3 elements there are 3 string comparisons, while computing a hash and managing hash slots have constant overhead. So there is a number of key elements, at which the sequential comparison is beaten by the hash search speed.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Does the mt4 b600+ has hash-arrays?
Would be great!
Gooly