alexbol99 / flatten-interval-tree

Interval binary search tree
MIT License
41 stars 21 forks source link

simple iterator implementation #46

Closed theSherwood closed 11 months ago

theSherwood commented 11 months ago

Thanks for the interval tree implementation. I found I need some kind of cursor implementation. This is WIP, but I wanted to get it on your radar. Is a cursor implementation something you're open to?

theSherwood commented 11 months ago

I've removed the bi-directionality (prev method on the cursor). Due to the bias of the sorting method, navigating backwards yields potentially surprising results. It would also be the only case of any api in the codebase that navigates backwards. So I removed it.

alexbol99 commented 11 months ago

Hi @theSherwood , This is a great contribution to the project. But isn't better to call this mechanism "iterator"? AFAIK "cursor" is typically associated with databases, where it represents the current position in a result set, not a traverse mechanism itself. What do you think?

theSherwood commented 11 months ago

@alexbol99 No problem! I'll make those changes and get it pushed up.

alexbol99 commented 11 months ago

@theSherwood , So maybe you can take it even one step further and implement it as iterable so that one can use for .. of loop? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators

theSherwood commented 11 months ago

@alexbol99 Sure. I can do that

theSherwood commented 11 months ago

@alexbol99 Good call. Using a generator function made things a lot simpler.

alexbol99 commented 11 months ago

Looks great! I will merge and release it tomorrow Thank you so much for collaboration

theSherwood commented 11 months ago

Great! Thanks for the quick turnaround on it all