LeveledSet#
- class LeveledSet(items=None)#
Bases:
object
A leveled set structure that keeps track of items at different levels.
Allows inserting new elements at a specific level.
Prevents duplicate entries across all levels.
Provides fast lookups to check if an item exists at any level.
Allows retrieval of all elements at a given level.
Supports batch insertion via extend().
Supports iteration, allowing use in min(), max(), and loops.
- __init__(items=None)#
Initializes an empty leveled set structure.
Methods
__init__
([items])Initializes an empty leveled set structure.
add
(item)Adds an item to the specified level, ensuring it hasn't been added before.
contains
(item)Checks if an item exists in any level.
difference
(other)Returns the difference of the global set with another set.
extend
(items)Adds multiple items at the specified level.
get_level
(level)Retrieves all items at a specific level.
intersection
(other)Returns the intersection of the global set with another set.
isdisjoint
(other)Checks if the global set has no elements in common with another set.
new_level
([items])Creates a new level if the last level contains items.
union
(other)Returns the union of the global set with another set.
- add(item)#
Adds an item to the specified level, ensuring it hasn’t been added before.
- Parameters:
item – The item (diagram) to add.
- contains(item)#
Checks if an item exists in any level.
- Parameters:
item – The item (diagram) to check.
- Returns:
True if the item exists, False otherwise.
- difference(other)#
Returns the difference of the global set with another set.
- Parameters:
other – The set to subtract.
- Returns:
A new set containing elements in the global set but not in other.
- extend(items)#
Adds multiple items at the specified level.
- Parameters:
items – An iterable of items to add.
- get_level(level)#
Retrieves all items at a specific level.
- Parameters:
level – The level to retrieve.
- Returns:
A set of items at the given level.
- intersection(other)#
Returns the intersection of the global set with another set.
- Parameters:
other – The set to intersect with.
- Returns:
A new set containing elements common to both sets.
- isdisjoint(other)#
Checks if the global set has no elements in common with another set.
- Parameters:
other – The set to check against.
- Returns:
True if the sets are disjoint, False otherwise.
- new_level(items=None)#
Creates a new level if the last level contains items.
- union(other)#
Returns the union of the global set with another set.
- Parameters:
other – The set to union with.
- Returns:
A new set containing all elements from both sets.