Mastering data structures in Ruby — Persistent lists

We have to take extra care each time we use it from our code, and, of course, never expose it to the public.The complexity of this method is O(n).privatedef self.copy src dst = src.each { |node| dst.insert } dstendWhen to use persistent data structuresI like to think of persistence as a nice side effect of not being able to afford updates in place. So any use-case that meets that constraint would be a nice fit for this kind of data structures.Also, if your code is tangled with mutexes and locks to coordinate execution on concurrent environments, you may want to give purely functional data structures a try. They are well suited to work in such settings.So that’s it for this brief introduction to persistent data structures. I hope you enjoyed it!As usual, you can get the code from here.Now that this series is done, what is next? I would probably do a short series on mastering algorithms in ruby as a follow up to this series. If you like it so far, stay tuned!Thanks for reading! Also, don’t forget to clap if you like this post :)PS: This post is part of a series on mastering data structures in Ruby, as we move forward subjects that were thoroughly discussed on previous posts are sometimes glossed over (if mentioned at all), if you want to get the most of this series, I recommend you to start from the very first post on singly linked list.. More details

Leave a Reply