from
The Object of My Callback
by Dimitri Shvorob
(object references with Matlab timers)
|
| CharKeyHashtable |
classdef CharKeyHashtable < handle
% ad hoc hash table class used by CallbackDemo.m
properties (SetAccess = private)
Keys
Vals
end
methods
function put(obj,key,val)
if isempty(obj)
obj.Keys = {key};
obj.Vals = {val};
else
obj.Keys{end+1} = key;
obj.Vals{end+1} = val;
end
end
function[val] = get(obj,key)
i = obj.index(key);
if isempty(i)
val = [];
else
val = obj.Vals{i};
end
end
function[out] = iskey(obj,key)
out = ~isempty(obj.index(key));
end
function[out] = isempty(obj)
out = isempty(obj.Keys);
end
end
methods (Access = private)
function[out]= index(obj,key)
out = [];
for i = 1:length(obj.Keys)
if strcmp(key,obj.Keys{i})
out = i;
break
end
end
end
end
end
|
|
Contact us at files@mathworks.com