# SortedCache S¶

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.

clearCache: () -> Void

clearCache() empties the cache.

enterInCache: (S, (S, S) -> Integer) -> S

enterInCache(x, f) enters x in the cache, calling f(x, y) to determine whether x < y (f(x, y) < 0), x = y (f(x, y) = 0), or x > y (f(x, y) > 0). It returns x with an integer associated with it.

enterInCache: (S, S -> Boolean) -> S

enterInCache(x, f) enters x in the cache, calling f(y) to determine whether x is equal to y. It returns x with an integer associated with it.

linearSearch: (S, S -> Boolean) -> Union(S, failed)

linearSearch(x, f) searches x in the cache, calling f(y) to determine whether x is equal to y. It returns y from cache such that f(y) or failed is no such y exists.