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

Set no more compatible with Collection #32

Closed
JJJHawk opened this issue Mar 25, 2018 · 5 comments
Closed

Set no more compatible with Collection #32

JJJHawk opened this issue Mar 25, 2018 · 5 comments
Assignees
Labels

Comments

@JJJHawk
Copy link

JJJHawk commented Mar 25, 2018

Hi Ding Li,

still I dont know how to make pull requests, so here is what I did local to make Set work again. I dont know, if that is all what is todo. But at least it should be the compatibility with the new iterator interface and with the new Collection constructor.

Greetings
Martin

` Collection/Set.mqh | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/Collection/Set.mqh b/Collection/Set.mqh
index efe3ee0..b6234c7 100644
--- a/Collection/Set.mqh
+++ b/Collection/Set.mqh
@@ -34,7 +34,7 @@ public:
// Iterator interface
Iterator*iterator() const {return new SetIterator(m_array);}
// for Set initial buffer set to zero

  •                 Set(int buffer=0):m_array(buffer){}
    
  •                 Set(bool owned=true,int buffer=0,EqualityComparer<T>*comparer=NULL):Collection<T>(owned,comparer),m_array(buffer){}
    
    // Collection interface
    void clear() {m_array.clear();}
    int size() const {return m_array.size();}
    @@ -89,5 +89,9 @@ public:
    void next() {if(!end()){m_index++;}}
    T current() const {return m_a[m_index];}
    bool set(T value) {m_a.set(m_index,value);return true;}
  • // MHO: so it fits the new interface
  • bool remove() {return true;} // safely remove current element
  • };
    //+------------------------------------------------------------------+
    `
@JJJHawk JJJHawk changed the title Set no more compatiblre with Collection Set no more compatible with Collection Mar 25, 2018
@JJJHawk
Copy link
Author

JJJHawk commented Mar 25, 2018

Still it doesn't work to make a simple Set of Integers for example:

m_strategies = new Set<int>();

Error is: Cannot instantiate abstract class

I dont find the reason but my changes above are not enough.

@yerden
Copy link
Contributor

yerden commented Mar 25, 2018

As you can see, Set's hierarchy of inheritance is ConstIterable->Iterable->Collection->Set. The latter one is an abstract class which you cannot instantiate. If you devise some implementation of a Set, you have to satisfy all ancestor classes' interfaces.

@dingmaotu
Copy link
Owner

@JJJHawk Hi what @yerden said is a future state, where the Set is an abstract class. You can use HashSet though, which is a concrete class that can be instantiated. Now the Set is an array based concrete implementation, but it is in a broken state as recently the collection classes had gone through a rather big refactoring and I don't have time to make it an ArraySet and turn the Set into an abstract interface. Sorry for the inconvenience. I will spend some time to close this issue.

Thank you for answering questions @yerden and your recent pull requests will be processed as soon as I have some time.

@JJJHawk
Copy link
Author

JJJHawk commented Mar 25, 2018

Hello Yerden,

yes I understand. That is why I changed the constructor in the Set-Class to:

Set(bool owned=true,int buffer=0,EqualityComparer<T>*comparer=NULL):Collection<T>(owned,comparer),m_array(buffer){}

which I took from the Vector Class, but unfortunately it doesn't help.

The line
m_strategies = new Set<int>();
worked fine before the last big update to Collection Classes.
The Set Constructor as it is now cannot work anymore so there is something to do:
Set(int buffer=0):m_array(buffer){}

I switched to Vector now and my code works again. Its OK. But I dont need any sorting mechanism so a set would be the better choice. I simply need Contains(). Its just a bucket for strategies with which I fill the EA. Like {1,3,4} means do strategies 1,3,4.

@JJJHawk
Copy link
Author

JJJHawk commented Mar 25, 2018

Hi Ding Li,

thank you very much for your answer which fits my last comment. Great work ! Thumbs Up!

Greetings
Martin

@dingmaotu dingmaotu self-assigned this Jun 22, 2018
@dingmaotu dingmaotu added the bug label Jun 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants