emilydolson / python-red-black-trees

Red-black tree implementation in Python
Other
20 stars 5 forks source link

Usage as a backend for a SET-like datastructure #8

Open thestics opened 1 year ago

thestics commented 1 year ago

I want to use your implementation for my data structure. In particular set would behave like this:

s = set()
s.add(1)
s.add(2)

# Logarithmic search
one_present = 1 in s

# Only one 2 is present
s.add(2)

As you might notice, in this case, the insertion of an already existing Node would just override the existing one, not insert it somewhere else. Do you think this is a useful addition and should I create a PR with that patch, or you're fine with the current implementation?

Cheers!

emilydolson commented 1 year ago

Thanks for the suggestion! The current implementation is intentionally a multi-set (i.e. it allows duplicate elements). Some of the examples in my algorithms class depend on that, so I'd like to keep it that way. However, if you want to add a second data-structure to the library that acts as a set, that would be totally welcome!