donmcbrien / RedBlackTree

An implementation of the red-black-tree algorithm in Swift
Other
1 stars 1 forks source link

Add a method for direct replacement #1

Open CTMacUser opened 2 months ago

CTMacUser commented 2 months ago

This method acts the same as a remove followed by an insert, but without churning the tree structure. It's especially helpful when the ordering predicate within the tree differs from the record type's Comparable implementation, assuming that even exists.

public mutating func replaceOne(with record: R) -> R?

If the record isn't in the tree at all, it is simply inserted. If duplicates are allowed, it is the existing record targeted for deletion by the FIFO vs LIFO rules that is replaced.

The outgoing record is returned, or nil if a new node had to be created.

donmcbrien commented 2 months ago

I can’t tell where this message came from but I’m intrigued. Please send me a link

On 20 Aug 2024, at 01:53, Daryle Walker @.***> wrote:

This method acts the same as a remove followed by an insert, but without churning the tree structure. It's especially helpful when the ordering predicate within the tree differs from the record type's Comparable implementation, assuming that even exists.

public mutating func replaceOne(with record: R) -> R? If the record isn't in the tree at all, it is simply inserted. If duplicates are allowed, it is the existing record targeted for deletion by the FIFO vs LIFO rules that is replaced.

The outgoing record is returned, or nil if a new node had to be created.

— Reply to this email directly, view it on GitHub https://github.com/donmcbrien/RedBlackTree/issues/1, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATOAGY6GV3QS7RO7ZVU4RR3ZSKARFAVCNFSM6AAAAABMYYZVH2VHI2DSMVQWIX3LMV43ASLTON2WKOZSGQ3TINBVGI4TSNQ. You are receiving this because you are subscribed to this thread.