annotate sequences/@cache/cache.m @ 2:7357e1dc2ad6
Simplified scheduler library with new schedule representation.
author |
samer |
date |
Sat, 22 Dec 2012 16:17:51 +0000 |
parents |
672052bd81f8 |
children |
|
rev |
line source |
samer@0
|
1 function o=cache(source)
|
samer@0
|
2 % CACHE- Cache each buffer to speed up multiple reads
|
samer@0
|
3 %
|
samer@0
|
4 % cache :: seq A -> seq A.
|
samer@0
|
5 %
|
samer@0
|
6 % The idea is that the data is cached on each call to NEXT,
|
samer@0
|
7 % so that reading the array does not require calls to source.
|
samer@0
|
8
|
samer@0
|
9 if nargin==0, o=cache(0);
|
samer@0
|
10 elseif isa(source,'cache'), o=source;
|
samer@0
|
11 else
|
samer@0
|
12 ft.datafn=@datafn;
|
samer@0
|
13 ft.stringfn=@stringfn;
|
samer@0
|
14 ft.nextfn=@cachenext;
|
samer@0
|
15 o.x=head(source);
|
samer@0
|
16 o=class(o,'cache',ddata(source,size(source),ft));
|
samer@0
|
17 end
|
samer@0
|
18
|
samer@0
|
19 function x=datafn(o), x=o.x;
|
samer@0
|
20 function s=stringfn(o), s='cache';
|
samer@0
|
21 function o=cachenext(o)
|
samer@0
|
22 o=next_c(o);
|
samer@0
|
23 if ~isempty(o), o.x=head(source(o)); end
|
samer@0
|
24
|
samer@0
|
25
|