Kalkwst / MicroLib

MIT License
3 stars 0 forks source link

:sparkles: Add SetUnique List Decorator #29

Open Kalkwst opened 1 year ago

Kalkwst commented 1 year ago

A set-unique list decorator is a layer of functionality that can be applied to an existing list data structure, allowing it to only store unique elements and automatically remove any duplicates. This can be useful for situations where the list should only contain unique elements and the user should not have to manually check for and remove duplicates.

From a more technical perspective, a set-unique list decorator is a design pattern that can be used to add a new layer of functionality to an existing data structure. It is used to ensure that the elements in an existing list are unique, by automatically removing any duplicates when they are added. The decorator pattern is implemented using inheritance and composition, where the decorator class inherits from the list class and adds new methods and/or fields to the list class. The decorator class wraps the existing list object and adds the new set-unique functionality by overriding the appropriate methods. The new methods of the decorator class use a set data structure to keep track of the unique elements, and this way, the decorator class can be easily added to any existing list and can be easily removed if it's not needed anymore. The time complexity of the search, insertion and deletion operations in a set-unique list decorator depends on the size of the list and the complexity of the set operations.