Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Are cons and snoc really O(n) operations? #237

Closed
JeffreyBenjaminBrown opened this issue Mar 15, 2019 · 3 comments
Closed

Are cons and snoc really O(n) operations? #237

JeffreyBenjaminBrown opened this issue Mar 15, 2019 · 3 comments

Comments

@JeffreyBenjaminBrown
Copy link

JeffreyBenjaminBrown commented Mar 15, 2019

That's what the documentation on Hackage says. I would have expected them to be O(1).

@chessai
Copy link
Member

chessai commented Mar 15, 2019

Edited your link to point to cons instead of the section on Folds.

@cartazio
Copy link
Contributor

yes, it has to. vectors are flat, prepending/appending a single element requires a vector with 1 additional slot! Theres perhaps alternative design approaches which would do a memmove/reallocation, but thats kinda not something in vector as its designed.

uncons/unsnoc can be O(1), via slicing.

if you know of an O(1) worst case approach that works for flat sequence in virtual memory structures rather than nested pointer/references, please do share.

@JeffreyBenjaminBrown
Copy link
Author

Ah, yes, of course, you're right. Thanks!

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

No branches or pull requests

3 participants