bagofstuff.history
Provides classes for handling different types of history.
NavigableHistory
Bases: SimpleHistory[T]
A history class that implements a linear navigation history.
When adding an item to the history, everything after the current location is removed from the history, and the new item is placed at the end.
add
Add an item to the history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
T
|
The item to add. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
Self. |
Note
When adding an item to the history, everything after the current location is removed from the history, and the new item is placed at the end.
RecencyHistory
Bases: SimpleHistory[T]
A history that keeps track of the most recent items.
The history attempts to stay unique, so if an item is added that already exists in the history, it is moved to the end of the history. Already existing is defined by an item that has equality to an item that already exists in the history.
SimpleHistory
SimpleHistory(
history: Sequence[T] | None = None,
max_length: int = 500,
)
Bases: Sequence[T]
A history class that implements a simple linear history.
Adding items to the list simple grows the list until the maximum length is reached, at which point the oldest items are removed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Sequence[T] | None
|
Set to the given history. |
None
|
|
int
|
Optional maximum length for the history. |
500
|
current_item
property
current_item: T | None
The current item in the history.
If there is no current item in the history the value is None.
current_location
property
current_location: int | None
The current integer location in the history.
If there is no valid location the value is None.
__getitem__
Get an item from the history.
add
Add an item to the history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
T
|
The item to add. |
required |
Returns:
| Type | Description |
|---|---|
Self
|
Self. |
Note
When adding an item to the history, everything after the current location is removed from the history, and the new item is placed at the end.
backward
backward() -> bool
Go backward through the history.
Returns:
| Type | Description |
|---|---|
bool
|
|
count
Return the number of occurrences of the given value in the history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
T
|
The value to count in the history. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The number of occurrences of the value in the history. |
forward
forward() -> bool
Go forward through the history.
Returns:
| Type | Description |
|---|---|
bool
|
|
index
Return the index of the given history item.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
T
|
The item to find in the history. |
required |
|
int
|
Optional start location. |
0
|
|
int
|
Optional stop location. |
maxsize
|
Returns:
| Type | Description |
|---|---|
int
|
The index of the item in the history. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the item is not in the history. |