SortedCache S¶
kl.spad line 14 [edit on github]
S: CachableSet
A sorted cache of a cachable set S
is a dynamic structure that keeps the elements of S
sorted and assigns an integer to each element of S
once it is in the cache. This way, equality and ordering on S
are tested directly on the integers associated with the elements of S
, once they have been entered in the cache.
- binarySearch: (S, (S, S) -> Integer) -> Union(S, failed)
binarySearch(x, f)
searchesx
in the cache, callingf(x, y)
to determine order. It returnsy
from cache iff
(x
,y
) is 0 or “failed” if no suchy
exists.
- clearCache: () -> Void
clearCache()
empties the cache.
- enterInCache: (S, (S, S) -> Integer) -> S
enterInCache(x, f)
entersx
in the cache, callingf(x, y)
to determine whetherx < y (f(x, y) < 0), x = y (f(x, y) = 0)
, orx > y (f(x, y) > 0)
. It returnsx
with an integer associated with it.
- enterInCache: (S, S -> Boolean) -> S
enterInCache(x, f)
entersx
in the cache, callingf(y)
to determine whetherx
is equal toy
. It returnsx
with an integer associated with it.
- linearSearch: (S, S -> Boolean) -> Union(S, failed)
linearSearch(x, f)
searchesx
in the cache, callingf(y)
to determine whetherx
is equal toy
. It returnsy
from cache iff
(y
) istrue
or “failed” if no suchy
exists.