Package elisa :: Package plugins :: Package bad :: Package poblenou_frontend :: Module list_cache
[hide private]
[frames] | no frames]

Module list_cache

source code

Classes [hide private]
  CacheList
A proxy list which purpose is to delay creation of its elements.
Functions [hide private]
tuple of int or None
substract(range1, range2)
Compute the difference between two ranges (range1[0], range1[1]) and (range2[0], range2[1]) (range1 - range2).
source code
tuple of int
cache(total, cached, index)
Given a total number of elements and a number of cached elements amongst them, compute which elements are currently cached.
source code
tuple of tuple of int
update_index(total, cached, old_index, new_index)
Given a total number of elements and a number of cached elements amongst them, compute which currently cached elements have to be removed and which ones have to be added for a change of index.
source code
int
insert(total, cached, index, inserted)
Given a total number of elements and a number of cached elements amongst them, compute the index of the cached element that has to be removed for an insertion at index inserted.
source code
int
remove(total, cached, index, removed)
Given a total number of elements and a number of cached elements amongst them, compute the index of the cached element that has to be added for a removal at index removed.
source code
Function Details [hide private]

substract(range1, range2)

source code 

Compute the difference between two ranges (range1[0], range1[1]) and (range2[0], range2[1]) (range1 - range2).

range1 cannot contain strictly range2. (eg.: (10, 20), (13, 17) is not allowed however (10, 20), (10, 17) is)).
Parameters:
  • range1 (tuple of int) - boundaries of the first range
  • range2 (tuple of int) - boundaries of the second range
Returns: tuple of int or None

cache(total, cached, index)

source code 
Given a total number of elements and a number of cached elements amongst them, compute which elements are currently cached.
Parameters:
  • total (int) - total number of elements
  • cached (int) - number of cached elements; inferior to total and odd
  • index (int) - the current index; must be between 0 and total-1
Returns: tuple of int

update_index(total, cached, old_index, new_index)

source code 
Given a total number of elements and a number of cached elements amongst them, compute which currently cached elements have to be removed and which ones have to be added for a change of index. It returns two ranges: the first one for the removed elements, the second one for the added elements (eg.: ((1,3), (5,6)), ((1,3), None)...).
Parameters:
  • total (int) - total number of elements
  • cached (int) - number of cached elements; inferior to total and odd
  • old_index (int) - the current index before the change; must be between 0 and total-1
  • new_index (int) - the current index after the change; must be between 0 and total-1
Returns: tuple of tuple of int

insert(total, cached, index, inserted)

source code 
Given a total number of elements and a number of cached elements amongst them, compute the index of the cached element that has to be removed for an insertion at index inserted. Returns None if no element has to be removed.
Parameters:
  • total (int) - total number of elements
  • cached (int) - number of cached elements; inferior to total and odd
  • index (int) - the current index; must be between 0 and total-1
  • inserted (int) - index of the newly inserted element; must be between 0 and total
Returns: int

remove(total, cached, index, removed)

source code 
Given a total number of elements and a number of cached elements amongst them, compute the index of the cached element that has to be added for a removal at index removed. Returns None if no element has to be added.
Parameters:
  • total (int) - total number of elements
  • cached (int) - number of cached elements; inferior to total and odd
  • index (int) - the current index; must be between 0 and total-1
  • removed (int) - index of the newly removed element; must be between 0 and total
Returns: int