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)searchesxin the cache, callingf(x, y)to determine order. It returnsyfrom cache iff(x,y) is 0 or “failed” if no suchyexists.
- clearCache: () -> Void
clearCache()empties the cache.
- enterInCache: (S, (S, S) -> Integer) -> S
enterInCache(x, f)entersxin 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 returnsxwith an integer associated with it.
- enterInCache: (S, S -> Boolean) -> S
enterInCache(x, f)entersxin the cache, callingf(y)to determine whetherxis equal toy. It returnsxwith an integer associated with it.
- linearSearch: (S, S -> Boolean) -> Union(S, failed)
linearSearch(x, f)searchesxin the cache, callingf(y)to determine whetherxis equal toy. It returnsyfrom cache iff(y) istrueor “failed” if no suchyexists.