processone / p1_utils

Erlang Utility Modules from ProcessOne
http://www.process-one.net/
Apache License 2.0
19 stars 26 forks source link

Request : Add last() to p1_queue #6

Open grizzly-monkey opened 7 years ago

grizzly-monkey commented 7 years ago

Can we please add functionality to get last element from queue()

Thanks Jeet

zinid commented 7 years ago

Only if we can make the operation O(1), which is doubtful without changing file queue format.

grizzly-monkey commented 7 years ago

what is current file queue format why will it not be done in o(1) can we not peek to the last entry ?

zinid commented 7 years ago

The current format is:

<<Size:32, BinaryTerm:Size/binary, ...>>

So, obviously, we can only peek in O(N) to the last element. In order to peek in O(1), we need to have something like:

<<Size:32, BinaryTerm:Size/binary, Size:32, ...>>
grizzly-monkey commented 7 years ago

Thanks for the clarity @zinid for now i am using ram queues so without changing p1_q i am managing last in my module. However if we can get this change in p1_q it would be awesome i am not sure how big this change format is for file queue but if we can get this it will be really great .

zinid commented 7 years ago

OK, I will try to look at it ASAP.

grizzly-monkey commented 7 years ago

Thank you Sir.