unlisted
ubuntu2004o
��c�( � @ s� d Z ddlmZ ddlZddlZddlmZ ddlZddl m
Z
ddlmZ G dd� de
�ZG d d
� d
e�Zej�ed�Zej�ed�Zee
e�Zeee�Zefd
d�Zefdd�Zefdd�Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� ZdS )z]
Cache of computations of top xi evaluations and various evaluation of tautological classes.
� )�literal_evalN)�DOT_SAGE)�ADM_EVAL_CACHE)�XI_TOP_CACHEc @ sF e Zd ZdZddd�Zdd� Zddd�Zd d
� Zddd
�Zdd� Z dS )�Cachea0
Dictionary with synchronization in a ``.sobj`` file.
TESTS:
The synchronization files stores only diffs::
sage: from admcycles.diffstrata.cache import Cache
sage: filename = tmp_filename(ext='.sobj')
sage: C = Cache({2: 'two'}, filename=filename)
sage: C[3] = 'three'
sage: D = Cache(filename=filename)
sage: D
{3: 'three'}
An example without synchronization file::
sage: C = Cache({2: 'two'})
sage: C[3] = 'three'
sage: C
{2: 'two', 3: 'three'}
Nc C sF || _ |d u ri | _t�| � n|�� | _t�| |� | �| j � d S �N)� _filename�_default�dict�__init__�copy�update_from_sobj_file)�self�values�filename� r �>/home/user/Introduction lectures/admcycles/diffstrata/cache.pyr ( s
zCache.__init__c C s | � � | �| j� dS )a�
Reset the content of the dictionary to the set of default values.
TESTS::
sage: from admcycles.diffstrata.cache import Cache
sage: C = Cache({1: 'ein', 2: 'zwei'})
sage: C[3] = 'drei'
sage: sorted(C.keys())
[1, 2, 3]
sage: C.reset_default()
sage: sorted(C.keys())
[1, 2]
N)�clear�updater )r r r r �
reset_default2 s zCache.reset_defaultc C sh |du r| j }|dur,tj�|�r.t�|�jr0| �tjj �
|�� || j kr2| �� dS dS dS dS dS )a�
Update the values of this dictionary from a ``.sobj`` file.
Missing or empty files are ignored. The cache file is synchronized.
EXAMPLES::
sage: from admcycles.diffstrata.cache import Cache
sage: filename1 = tmp_filename(ext='.sobj')
sage: filename2 = tmp_filename(ext='.sobj')
sage: C1 = Cache({2: 'two'}, filename=filename1)
sage: C1[3] = 'three'
sage: C2 = Cache(filename=filename2)
sage: C2
{}
sage: C2.update_from_sobj_file(filename1)
sage: Cache(filename=filename2)
{3: 'three'}
N)r �os�path�isfile�stat�st_sizer �sage�misc�persist�load�save_to_sobj_file)r r r r r r
D s �
�
�zCache.update_from_sobj_filec C s | � � }| jD ]}||= q|S r )r r )r �cache�keyr r r �diff` s
z
Cache.diffTc C sJ |du r| j }|dur!|r| �� n| �� }|r#tjj�||� dS dS dS )zI
Save the values of this dictionary to a ``.sobj`` file.
N)r r"