Julia set data structure


#1

I have a question on the set data structure in base Julia. As far as I understand, it is mutable, with O(1) membership, and adding an element is done with push!, which modifies the set.

Is there a “functional” set collection that is immutable and for which “adding” elements proceeds by sharing? Or a simple way to emulate this behavior with the default set structure? At the moment, I am using

 (s,x) -> union(s, Set(x))

in order to get a new set with x added without modifying s but it is probably not very efficient.


#2

https://github.com/JuliaLang/FunctionalCollections.jl ?


#3

That was written a while ago and has had very light maintenance, but it may work.


#4

Well, it’s code is very simple. The tests fail, but it probably just needs some PRs to update from deprecated syntax. Sounds like a very good contribution opportunity for a newcomer.


#5

Chris, I was glad to see such an opportunity pointed out. Thanks!

I gave it a go here https://github.com/JuliaLang/FunctionalCollections.jl/pull/29 and would appreciate any help in improving the PR until it is useful :slight_smile: