Add vision of Python API
This commit is contained in:
parent
b273772722
commit
a09b71cdb3
2 changed files with 62 additions and 3 deletions
|
@ -1 +1,46 @@
|
|||
def sum_as_string(a: int, b: int) -> str: ...
|
||||
from typing import Self
|
||||
|
||||
|
||||
class PureQueue[T]:
|
||||
"""A min-queue that allows duplicates and provides a minimal API allowing insertions and the ability to iterate over the queue in-order"""
|
||||
def __init__(self, items: dict[T, float] | None = None) -> None:
|
||||
"""
|
||||
:param items: An optional mapping of items to priorities to initialize the queue with
|
||||
"""
|
||||
|
||||
def __len__(self) -> int:
|
||||
"""
|
||||
:return: The number of items in the queue
|
||||
"""
|
||||
|
||||
def __iter__(self) -> Self:
|
||||
"""
|
||||
:return: An iterator over the queue
|
||||
"""
|
||||
|
||||
def __next__(self) -> T:
|
||||
"""
|
||||
:return: The next item in the queue
|
||||
"""
|
||||
|
||||
def __setitem__(self, key: T, value: float) -> None:
|
||||
"""
|
||||
Inserts a new item into the queue
|
||||
:param key: The item to insert
|
||||
:param value: The priority of the item
|
||||
"""
|
||||
|
||||
|
||||
class KeyedQueue[T](PureQueue[T]):
|
||||
"""A min-queue that disallows duplicates but offers the ability to update priorities and delete arbitrary items"""
|
||||
def __setitem__(self, key: T, value: float) -> None:
|
||||
"""
|
||||
Inserts an item into the queue, or updates its priority if it already exists
|
||||
:param key: The item to insert or update
|
||||
:param value: The priority of the item
|
||||
"""
|
||||
|
||||
def __delitem__(self, key: T) -> None:
|
||||
"""
|
||||
:param key: The item to delete from the queue
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue