o
�Ul_0B � @ sz d Z ddlZddlZddlZddlmZ ddlmZ ddlm Z G dd� de
ee �ZG dd � d ee �ZG d
d� de�Z
dS )a�
Improved container classes
==========================
The ``containers`` module defines improved container classes, such as lists:
* `List`: a subclass of the builtin ``list`` class, with added methods, such as ``index_append``;
* `Bijectivelist`: a replacement for the ``list`` class for use with 1-1 relationships
where index lookup via ``dict`` makes sense; and
* `ShelveBijectivelist`: a replacement for the ``list`` class for use with 1-1 relationships
where index lookup via ``shelve`` makes sense.
This class uses ``shelve`` to cope with cases where a ``dict`` would be too large to store in memory.
AUTHORS:
- Paul Leopardi (2016-08-21): initial version
� N)�tmp_filename)�
SageObject)�Saveablec @ s e Zd ZdZdd� ZdS )�Lista�
Subclass of ``list`` with added methods, such as ``index_append``.
TESTS:
::
sage: from boolean_cayley_graphs.containers import List
sage: L = List([1,2,4])
sage: print(L)
[1, 2, 4]
sage: from boolean_cayley_graphs.containers import List
sage: L = List([1,2,4])
sage: latex(L)
\text{\texttt{[1,{ }2,{ }4]}}
c C s8 z| � |�}W |S ty t| �}| �|� Y |S w )ax
Return the index of a given item, appending it if necessary.
If the inherited list ``index`` method for ``self`` yields a ``ValueError`,
then set result to the length of `self``, and append item to ``self``.
INPUT:
- ``self`` -- the current object.
- ``item`` -- the item to look up, and append if necessary.
OUTPUT:
A non-negative integer indicating the index of ``item`` within ``self``.
EFFECT:
The item ``item`` may be appended to ``self``.
EXAMPLES:
::
sage: from boolean_cayley_graphs.containers import List
sage: L = List([1,2,4])
sage: L.index_append(2)
1
sage: L
[1, 2, 4]
sage: L.index_append(3)
3
sage: L
[1, 2, 4, 3]
sage: del L
)�index�
ValueError�len�append��self�item�result� r �D/home/user/Boolean-Cayley-graphs/boolean_cayley_graphs/containers.py�index_append: s $��zList.index_appendN)�__name__�
__module__�__qualname__�__doc__r r r r r r &