SamanthaDawsonBanks / MCOMP_Team_Project_2017-2018

MIT License
6 stars 1 forks source link

popping (polling) an empty queue #10

Closed SamanthaDawsonBanks closed 6 years ago

SamanthaDawsonBanks commented 6 years ago

what do we want to do if we try to 'pop' [technically you 'poll' a queue you 'pop' a stack] so 'poll' an empty queue?

one option is to return null but then we need to check all results for null.

another option is the Optional but that has issues with serializable (and thus RMI)

another option is to always return the last result (so the queue never goes empty) but that might explode for other reasons??

stevempope commented 6 years ago

The queue refers to the Path object does it not? In the constructor for a path, the destination should always be present, meaning we can’t ever reach that condition?

Another solution is to have a getter for the length and to poll that private variable instead of making a direct call to the queue. This keeps the bigO performance in a nice range too.

SamanthaDawsonBanks commented 6 years ago

Yes the queue should say path, sorry I was in theory mode when I posted.

And yes, at least one node will be supplied to the constructor, but what happens if:

NumOfPolls > NumOfAdds +1

We create a path(suppling 1 node) add n nodes poll the path n times (meaning that it now only contains 1 node) poll it for the last node (destination) Then poll it again

SamanthaDawsonBanks commented 6 years ago

Ok one change idea for the path object: on creation must supply one waypoint (referred to as the 'destination') other waypoints can be supplied via method (referred to as 'midpoints' [or other suggestions of a name]) polling a path will give one midpoint on a FIFO bases, unless there are no remaining midpoints in which case it will return the destination, the destination is never removed from the path (so it will always be returned on polling an 'empty' path)

SamanthaDawsonBanks commented 6 years ago

possible fix in #12