langtree.core.buffer¶
Module Contents¶
Classes¶
A class to represent a buffer with a fixed length. |
- class langtree.core.buffer.Buffer(length)[source]¶
A class to represent a buffer with a fixed length.
This buffer allows appending and extending its content while ensuring it never exceeds its defined length. If the buffer’s content exceeds its length, items are removed from the beginning.
- property memory¶
Provide access to the buffer’s memory.
- Returns:
The buffer’s memory content.
- Return type:
list
- append(item)[source]¶
Append an item to the buffer and ensure the buffer does not exceed its length.
- Parameters:
item – The item to append.
- extend(item_list)[source]¶
Extend the buffer with a list of items and ensure the buffer does not exceed its length.
- Parameters:
item_list (list) – The list of items to extend the buffer with.
- _shrink()[source]¶
Private method to shrink the buffer to its defined length by removing items from the beginning.
- __add__(item)[source]¶
Handle addition operations with the buffer. Allows for adding a single item or a list of items.
- Parameters:
item – An item or a list of items to add.
- Returns:
The updated buffer.
- Return type: