robtillaart:
You use a linked list for the PCintPin objects.
you could keep this list in sorted order to speed up the average search time of void PCintPort::PCint()
On average the nr of search steps would be half of the current implementation,
- addPin would be slightly complexer to keep the list sorted. - C++ Add to linked list in sorted order - Stack Overflow -
- addPin could detect that the pin already has in ISR() attached.
- delPin does not need to change as it already can delete from the middle of the list
it might be more robust to add a return value for addPin and delPin that indicates the #pins added /delete. addPin might return -1 if pin exist.
These values can be propagated to attachInterrupt/detachIRQ.
Thanks for the feedback, Rob.
I had considered the sorted linked list, but then I realized that sorting on pin number may not be what the user wants. It only speeds up the average search time if you can guarantee an even distribution of interrupts. I would rather let the programmer decide in which order he or she decides to add pins.
Having addPin() and attachInterrupt() return values seems pretty easy and somewhat smart, so I will look into doing that.