A simple cache that can be used to store results of computations.


function varargout = simpleCache( op, cache, varargin )


 A simple cache that can be used to store results of computations.

 Can save and retrieve arbitrary values using a vector (includnig char
 vectors) as a key. Especially useful if a function must perform heavy
 computation but is often called with the same inputs (for which it will
 give the same outputs).  Note that the current implementation does a
 linear search for the key (a more refined implementation would use a hash
 table), so it is not meant for large scale usage.

 To use inside a function, make the cache persistent:
  persistent cache; if( isempty(cache) ) cache=simpleCache('init'); end;
 The following line, when placed inside a function, means the cache will
 stay in memory until the matlab environment changes.  For an example
 usage see maskGaussians.

 USAGE - 'init': initialize a cache object
  cache = simpleCache('init');

 USAGE - 'put': put something in cache.  key must be a numeric vector
  cache = simpleCache( 'put', cache, key, val );

 USAGE - 'get': retrieve from cache.  found==1 if obj was found
  [found,val] = simpleCache( 'get', cache, key );

 USAGE - 'remove': free key
  [cache,found] = simpleCache( 'remove', cache, key );

  op         - 'init', 'put', 'get', 'remove'
  cache      - the cache object being operated on
  varargin   - see USAGE above

  varargout  - see USAGE above

  cache = simpleCache('init');
  hellokey=rand(1,3); worldkey=rand(1,11);
  cache = simpleCache( 'put', cache, hellokey, 'hello' );
  cache = simpleCache( 'put', cache, worldkey, 'world' );
  [f,v]=simpleCache( 'get', cache, hellokey ); disp(v);
  [f,v]=simpleCache( 'get', cache, worldkey ); disp(v);


 Piotr's Computer Vision Matlab Toolbox      Version 2.61
 Copyright 2014 Piotr Dollar.  []
 Licensed under the Simplified BSD License [see external/bsd.txt]

Generated by m2html © 2003