jermp / sshash

A compressed, associative, exact, and weighted dictionary for k-mers.
MIT License
84 stars 17 forks source link

Default constructor to the iterator #3

Closed shokrof closed 2 years ago

shokrof commented 2 years ago

Hey, I am using sshash as submodule in my project. It will make my life much easier if you added an empty constructor for dictionary::iterator. I am getting this error "error: no matching function for call to ‘sshash::dictionary::iterator::iterator()’". I am not using the constructor directly but I am keeping an iterator as a member in my classes.

Thanks, Moustafa

jermp commented 2 years ago

Hi, that could be done of course but: why not keeping a pointer to an object of type sshash::dictionary and then using the pointer to get the iterator, e.g., auto it = obj->begin()?

shokrof commented 2 years ago

Hi, I think it won't work because I want to keep the iterator data during the lifetime of my class. It is not recommended to make a pointer point to a memory on the stack(created by obj->begin()).

shokrof commented 2 years ago

I fixed for myself. I used pointer and created its value using "new iterator(dictionary pointer)". then I used it with dictionary::begin() and dictionary::at()

Thanks

jermp commented 2 years ago

The pointer obj in my previous answer is a pointer to a dictionary object, not a pointer to an iterator. The dictionary's memory is not allocated on the stack. So your class can either include an object sshash::dictionary as a private member of have a pointer to it if you do not want to explicitly manage its memory.

If you keep an iterator as member of your class, then how would you initialize it? You will need to do something like: it = iterator(dictionary const* ptr). So you need a pointer to a dictionary object and the best thing to do is to keep it as I mentioned before. Hope it is clear now. If not, let me know -- I'm glad to help.

shokrof commented 2 years ago

yeah, I got thank you