davecom / SwiftGraph

A Graph Data Structure in Pure Swift
Apache License 2.0
758 stars 80 forks source link

Does a graph have to be mutable? #88

Closed Vithanco closed 3 weeks ago

Vithanco commented 3 weeks ago

I would like to create a struct that adheres to the Graph Protocol. However, the protocol has setters as requirements, making it impossible to implement an immutable graph structure. I assume that the algorithms don't need a MutableGraph.

Would you be open to a separation into Graph and MutableGraph? I could do a PR, but would need indication that it is of interest before. ;-)

davecom commented 3 weeks ago

What's the use case?

Vithanco commented 3 weeks ago

I am working on some functional code. I want to create rather a new graph then changing the old one.

davecom commented 3 weeks ago

I guess I don't understand. Why can't you just not mutate it? Just because there are mutable methods there, it doesn't mean you have to use them.

Vithanco commented 3 weeks ago

Of course, that is a possibility. I guess, i have my answer - and I fine with it. ;-)