view 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
line wrap: on
line source
function o=cache(source)
% CACHE- Cache each buffer to speed up multiple reads
%
% cache :: seq A -> seq A.
%
% The idea is that the data is cached on each call to NEXT,
% so that reading the array does not require calls to source.

if nargin==0, o=cache(0);
elseif isa(source,'cache'), o=source;
else
	ft.datafn=@datafn;
	ft.stringfn=@stringfn;
	ft.nextfn=@cachenext;
	o.x=head(source);
	o=class(o,'cache',ddata(source,size(source),ft));
end

function x=datafn(o), x=o.x;
function s=stringfn(o), s='cache';
function o=cachenext(o)
	o=next_c(o);
	if ~isempty(o), o.x=head(source(o)); end