Skip to content

add Fifo.length function#8

Open
fredcy wants to merge 2 commits into
avh4:masterfrom
fredcy:length
Open

add Fifo.length function#8
fredcy wants to merge 2 commits into
avh4:masterfrom
fredcy:length

Conversation

@fredcy
Copy link
Copy Markdown

@fredcy fredcy commented Apr 27, 2022

My app frequently wants to know the length of the Fifo (for display to the user) and the Fifo can grow to be thousands of items long, so I want a fast way to obtain that length value. I could use Fifo.toList |> List.length but that involves both list reversal (within toList) and traversal again (in List.length) on each call.

So this change has the Fifo keep its current length as part of the state. This does mean additional work on every insert, remove, and toList call to recalculate that length. I have not benchmarked any times before and after this change.

If this PR is unacceptable, please let me know and I'll probably publish my forked version as a new package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant